题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1176
题解:
dp[i][j]表示第i秒时在位置j时包里的馅饼;
如果把每一刻能否得到馅饼画出来,大致就是这个样子
第0秒 5
第1秒 4 5 6
第2秒 3 4 5 6 7
第3秒 2 3 4 5 6 7 8
第4秒 1 2 3 4 5 6 7 8 9
第5秒 0 1 2 3 4 5 6 7 8 9 10
第6秒 0 1 2 3 4 5 6 7 8 9 10
第7秒 .................
如果当前位置有馅饼,dp值就是1,否则是0
然后就是最简单的数塔了,是取三个位置的最大值
dp[i][j]=max{dp[i+1][j],dp[i+1][j-1],dp[i+1][j+1]}+value[i][j];
至于0这个位置,可以把坐标轴右移一位,就不需要特判了
还是很水的一道题
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,dp[200010][20];
int main()
{
int t,x,maxt,nmax;
while(scanf("%d",&n)&&n)
{
memset(dp,0,sizeof(dp));
maxt=0;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&x,&t);
dp[t][x+1]++;
maxt=max(maxt,t);
}
for(int i=maxt-1;i>=0;i--)
for(int j=1;j<=11;j++)
{
nmax=max(dp[i+1][j-1],dp[i+1][j]);
nmax=max(dp[i+1][j+1],nmax);
dp[i][j]+=nmax;
}
printf("%d\n",dp[0][6]);
}
return 0;
}