HDU-1176 免费馅饼

来源:互联网 发布:淘宝证件相片拍摄 编辑:程序博客网 时间:2024/05/20 21:49

这道题的思想前辈,已经讲过了。代码当然是根据前辈的思想写的。

AC代码:

#include<iostream>#include<cstdio>#include<cstring>using namespace std;int number[13][100010];int n,x,t,max_t,max_x,max_three;void DP(){    for(int j = max_t - 1; j >= 0 ; j--)        for(int i = 1; i <= max_x; i++)        {            max_three = number[i - 1][j + 1];            if(max_three < number[i][j + 1])                max_three = number[i][j + 1];            if(max_three < number[i + 1][j + 1])                max_three = number[i + 1][j + 1];            number[i][j] += max_three;        }    printf("%d\n",number[6][0]);}int main(){    while(scanf("%d",&n))    {        if(n == 0)            break;        memset(number,0,sizeof(number));        max_t = max_x = 0;        for(int i = 0; i < n; i++)        {            scanf("%d %d",&x,&t);            number[++x][t]++;            if(t > max_t)                max_t = t;            if(x > max_x)                max_x = x;        }        DP();    }    return 0;}

END

0 0
原创粉丝点击