标签:
免费馅饼
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 28601 Accepted Submission(s): 9760
for(int i=1;i<=11;i++)
dp[i][time]=max(sum[i][time],sum[i+1][time],sum[i-1][time]);
因为这题的意思是你在每一秒都可以在3格之内移动。
下面是ac代码
#include<cstdio>
#include<cstring>
#include<iostream>
int dp[13][100005],sum[13][100005];
using namespace std;
int max(int a,int b,int c)
{
a=a>b?a:b;
return a>c?a:c;
}
int main()
{
int n,x,t;
while(scanf("%d",&n),n)
{
memset(dp,0,sizeof(dp));
memset(sum,0,sizeof(sum));
int time=0;
for(int i=0;i<n;i++)
{
scanf("%d%d",&x,&t);
sum[x+1][t]++;
time=time>t?time:t;
}
for(int i=1;i<=11;i++)
dp[i][time]=max(sum[i][time],sum[i+1][time],sum[i-1][time]);
for(int i=time-1;i>=1;i--)
{
for(int j=1;j<=11;j++)
{
dp[j][i]=max(dp[j-1][i+1]+sum[j-1][i],dp[j+1][i+1]+sum[j+1][i],dp[j][i+1]+sum[j][i]);
}
}
printf("%d\n",dp[6][1]);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/lthb/p/4351853.html