http://acm.hdu.edu.cn/showproblem.php?pid=1176
简单dp,转换后跟上一题数塔一样,注意每秒只能移动一格,还有在边缘的情况。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int a[100005][12]; int maxx(int x,int y,int z) { int temp = max(x,y); return max(temp,z); } int main() { int n; while(scanf("%d",&n) && n) { memset(a,0,sizeof(a)); int time = 0; while(n--) { int t,x; scanf("%d%d",&x,&t); time = max(time,t); a[t][x]++; } for(int i = time-1;i >= 0;i--) { for(int j = 1;j < 10;j++) a[i][j] += maxx(a[i+1][j],a[i+1][j-1],a[i+1][j+1]); a[i][0] += max(a[i+1][0],a[i+1][1]); a[i][10] += max(a[i+1][10],a[i+1][9]); } printf("%d\n",a[0][5]); } return 0; }