hdu1176 免费馅饼(变形数塔)

来源:互联网 发布:手机游戏编程 编辑:程序博客网 时间:2024/05/19 00:14

hdu1176

#include<algorithm>#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>using namespace std;int data[100005][11];int temp[100005][11];int main(){    int n;    while(scanf("%d",&n)!=-1)    {        if(n==0) break;        memset(data,0,sizeof(data));        memset(temp,0,sizeof(temp));        int t=0;        while(n--)        {            int a,b;            scanf("%d%d",&a,&b);            data[b][a]++;            if(t<b) t=b;        }        for(int i=0;i<=10;i++)        {            temp[t][i]=data[t][i];        }        for(int i=t-1;i>=0;i--)        {            for(int j=0;j<=10;j++)            {                if(j==0) temp[i][j]=max(temp[i+1][j],temp[i+1][j+1])+data[i][j];                else if(j==10) temp[i][j]=max(temp[i+1][j],temp[i+1][j-1])+data[i][j];                else temp[i][j]=max(max(temp[i+1][j],temp[i+1][j+1]),temp[i+1][j-1])+data[i][j];            }        }        printf("%d\n",temp[0][5]);    }    return 0;}


0 0