HDU 1176 免费馅饼

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1176

解题思路:

本题是简单的数塔dp。

可以参考博客:

http://blog.csdn.net/theonegis/article/details/45801201

实现代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAXN=100010;
const int INF=1<<20;
int data[MAXN][14];
int dp[MAXN][14];

int main(){
    int n;
    while(scanf("%d",&n)!=EOF&&n){
        memset(data,0,sizeof(data));
        memset(dp,0,sizeof(dp));

        int MAXT=-INF;
        for(int i=0;i<n;i++){
            int x,T;
            scanf("%d%d",&x,&T);
            data[T][x+1]++;         //注这儿的x都加了1
            MAXT=max(MAXT,T);
        }

        for(int i=MAXT;i>=0;i--){
            for(int j=1;j<=11;j++)
                dp[i][j]=max(dp[i+1][j],max(dp[i+1][j-1],dp[i+1][j+1]))+data[i][j];
        }

        printf("%d
",dp[0][6]);
    }
}
自己选的路,跪着也要把它走完------ACM坑
原文地址:https://www.cnblogs.com/IKnowYou0/p/6604559.html