标签:str cstring cst alt ring article ++ problem style
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1176
解题思路:
本题是简单的数塔dp。
可以参考博客:
http://blog.csdn.net/theonegis/article/details/45801201
实现代码:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN=100010; const int INF=1<<20; int data[MAXN][14]; int dp[MAXN][14]; int main(){ int n; while(scanf("%d",&n)!=EOF&&n){ memset(data,0,sizeof(data)); memset(dp,0,sizeof(dp)); int MAXT=-INF; for(int i=0;i<n;i++){ int x,T; scanf("%d%d",&x,&T); data[T][x+1]++; //注这儿的x都加了1 MAXT=max(MAXT,T); } for(int i=MAXT;i>=0;i--){ for(int j=1;j<=11;j++) dp[i][j]=max(dp[i+1][j],max(dp[i+1][j-1],dp[i+1][j+1]))+data[i][j]; } printf("%d\n",dp[0][6]); } }
标签:str cstring cst alt ring article ++ problem style
原文地址:http://www.cnblogs.com/IKnowYou0/p/6604559.html