NYoj 613 免费馅饼
#include<cstdio>
#include<cstring>
#define Max(a,b) (a>b?a:b)
#define max 100000+5
int dp[max][11]; //dp[i][j]表示在i秒时站在j点处可得到的馅饼个数的最大值
int map[max][11]; //把每秒钟每个坐标的馅饼个数存储在map矩阵中
int MAX(int a,int b,int c){
if(a<b){
a=b;
}
if(a<c){
a=c;
}
return a;
}
int main(){
int n;
while(~scanf("%d",&n)&&n){
memset(dp,0,sizeof(dp));
memset(map,0,sizeof(map));
int s=0;
for(int i=0;i<n;i++){
int x,t;
scanf("%d%d",&x,&t);
map[t][x]++;
if(t>s){
s=t;
}
}
int ans=0,l,r;
l=4;r=6;//初始为5,所以有可能获得馅饼的坐标为4,5,6
for(int i=1;i<=s;i++){
for(int j=l;j<=r;j++){
if(j==0){
dp[i][j]=Max(dp[i-1][j],dp[i-1][j+1])+map[i][j];
}
else if(j==10){
dp[i][j]=Max(dp[i-1][j-1],dp[i-1][j])+map[i][j];
}
else{
dp[i][j]=MAX(dp[i-1][j-1],dp[i-1][j],dp[i-1][j+1])+map[i][j];
}
if(ans<dp[i][j]){
ans=dp[i][j];
}
}
l--;l=(l<0?0:l);//更新l,r
r++;r=(r>10?10:r);
}
printf("%d\n",ans);
}
}
posted on 2013-06-23 17:22 Stomach_ache 阅读(100) 评论(0) 编辑 收藏 举报