/*状态:dp[i][j], 表示人在第i秒在j个位置上所得到的最大馅饼数
状态转移: dp[i][j] += max(dp[i+1][j], dp[i+1][j-1], dp[i+1][j+1])*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAXCOL 11
#define MAXROW 100001
unsigned long long dp[MAXROW][MAXCOL];
unsigned long long dynamic_programming(int max_v)
{
unsigned long long val = 0;
for(int i = max_v-1; i >= 1; i --) {
for(int j = 0; j < MAXCOL; j ++) {
val = dp[i+1][j];
if( j-1 >= 0 ) {
val = max(val, dp[i+1][j-1]);
}
if( j+1 < MAXCOL ) {
val = max(val, dp[i+1][j+1]);
}
dp[i][j] += val;
}
}
return max(max(dp[1][4], dp[1][5]), dp[1][6]);
}
int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
freopen("test.in", "r", stdin);
#endif
int n, x, y, max_v;
while( scanf("%d", &n) && n ) {
max_v = 0;
memset(dp, 0, sizeof(dp));
for(int i = 0; i < n; i ++) {
scanf("%d %d", &y, &x);
dp[x][y] ++;
max_v = max(max_v, x);
}
printf("%lld\n", dynamic_programming(max_v));
}
return 0;
}
hdu_1176
最新推荐文章于 2019-11-11 22:00:58 发布