HDU 1176 免费馅饼

其实就是数塔问题,由后往前推!

code:

#include <iostream>
using namespace std;

 

int max(int a,int b,int c)
{
    int temp = a;
    if(temp < b)
        temp = b;
    if(temp < c)
        temp = c;
    return temp;
}

int dp[100004][11];

int main()
{
    int n,i,j,x,T,tMax = 0;
    while(scanf("%d\n",&n) && n)
    {    
        tMax = 0;
        memset(dp,0,sizeof(dp));
        while(n--)
        {
            scanf("%d %d",&x,&T);
            dp[T][x]++;
            if(tMax<T)tMax=T ;
        }

        for(i=tMax-1;i>=0;i--)
        {
            dp[i][0] += max(dp[i+1][0],dp[i+1][1]);
            for(j=1;j<10;j++)
                dp[i][j] += max(dp[i+1][j-1],dp[i+1][j+1],dp[i+1][j]);
            dp[i][10] += max(dp[i+1][9],dp[i+1][10]);
        }
        printf("%d\n",dp[0][5]);
    }
    return 0;
}

posted on 2010-02-27 20:48  forward power  阅读(205)  评论(0编辑  收藏  举报