hdoj 1176 免费馅饼

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1176

解题思路:核心为 dp[x][T]=dp[x][T]+max(dp[x-1][T+1],dp[x][T+1],dp[x+1][T+1]), 其中 1≤x≤11, 0≤T<Tmax. 答案为 dp[6][0].

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 
 5 int dp[15][100005];
 6 
 7 int max(int x,int y,int z){
 8     if(y>x) x=y;
 9     if(z>x) x=z;
10     return x;
11 }
12 
13 int main(){
14     int n,x,T;
15     while(scanf("%d",&n)!=EOF){
16         if(n==0) break;
17         for(x=0;x<15;x++){
18             for(T=0;T<100005;T++) dp[x][T]=0;
19         }
20         int Tmax=0;
21         while(n--){
22             scanf("%d%d",&x,&T);
23             dp[x+1][T]++;
24             if(T>Tmax) Tmax=T;
25         }
26         for(T=Tmax-1;T>=0;T--){
27             for(x=1;x<=11;x++){
28                 dp[x][T]+=max(dp[x-1][T+1],dp[x][T+1],dp[x+1][T+1]);
29             }
30         }
31         printf("%d\n",dp[6][0]);
32     }
33     return 0;
34 }

 

posted on 2013-06-28 13:21  SCNU20102200088  阅读(194)  评论(0编辑  收藏  举报

导航