HDOJ1176 Posted on 2018-03-12 HDOJ1176 作为一个弱鸡,这道题目花了我很长的时间orz,首先花了很长的时间去理解这道题其实和数塔(ACM2084)实质其实一模一样,甚至连代码都差不多orz 1234567891011121314151617181920212223242526272829303132333435363738#include<iostream>#include<algorithm>#include<cstring>using namespace std;#define MAXN 140000int a[MAXN][11];int main(){ int n, position, time; while (cin>>n&&n) { int max_time = 0; memset(a, 0, sizeof(a)); for (int i = 0; i < n; i++) { scanf_s("%d%d", &position, &time); a[time][position]++; max_time = max(max_time, time); } for (int i = max_time - 1; i >= 0; i--) { for (int j = 0; j <= 10; j++) { if(j==0) { a[i][j] += max(a[i + 1][j], a[i + 1][j +1]); continue; } if(j==10) { a[i][j] += max(a[i + 1][j], a[i + 1][j - 1]); continue; } a[i][j] += max(max(a[i + 1][j ], a[i + 1][j+1]), a[i + 1][j - 1]); } } cout << a[0][5] << endl; } return 0;}