标签:blog http io ar os sp for 数据 div

6 5 1 4 1 6 1 7 2 7 2 8 3 0
4
/*
状态方程 f(i,j)=max(f(i+1,j) ,f(i+1,j+1) ,f(i+1,j-1));
表示第i秒到j位置能得到的最大收益
a[i][j] :第i秒在j位置掉落的馅饼数量
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
using namespace std;
const int maxn=10010;
int n,a[maxn][14],f[maxn][14],maxf;
int main()
{
while(scanf("%d",&n),n)
{
maxf=0;
memset(f,0,sizeof(f));
for(int i=1;i<=n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
f[y][x]++;
if(y>maxf)
maxf=y;
}
for(int i=maxf-1;i>=0;i--)
for(int j=0;j<=10;j++)
if(j==0)
f[i][j]+=max(f[i+1][j],f[i+1][j+1]);
else
f[i][j]+=max(max(f[i+1][j],f[i+1][j+1]),f[i+1][j-1]);
printf("%d\n",f[0][5]);
}
return 0;
}
标签:blog http io ar os sp for 数据 div
原文地址:http://www.cnblogs.com/a972290869/p/4099949.html