hdu1176

看了看题 没什么想法 参考着解题报告写的

状态方程 dp[i][j] = max{dp[i+1][j],dp[i+1][j+1],dp[i+1][j-1]}

View Code
 1 #include <stdio.h>
 2 #include<string.h>
 3 int dp[100001][12];
 4 int max1(int x, int y, int z)
 5 {
 6     int m = x;
 7     if(m<y)
 8     m = y;
 9     if(m<z)
10     m = z;
11     return m;
12 }
13 int main()
14 {
15     int n,i, j,b,t;
16     while(scanf("%d", &n)&&n)
17     {
18         int max = 0;
19         memset(dp,0,sizeof(dp));
20         for(i = 1 ; i <= n ; i++)
21         {
22             scanf("%d%d",&b,&t);
23             dp[t][b]++;
24             if(t>max)
25             max = t;
26         }
27         dp[0][5] = 0;
28         for(i = max-1 ; i >= 0 ; i--)
29         for(j = 0 ; j <= 10 ; j++)
30         {
31             if(j==0)
32             {
33                 if(dp[i+1][j]>dp[i+1][j+1])
34                 dp[i][j] += dp[i+1][j];
35                 else
36                 dp[i][j] += dp[i+1][j+1];
37             }
38             else
39             if(j == 10)
40             {
41                 if(dp[i+1][j]>dp[i+1][j-1])
42                 dp[i][j] += dp[i+1][j];
43                 else
44                 dp[i][j] += dp[i+1][j-1];
45             }
46             else
47             {
48                 dp[i][j] += max1(dp[i+1][j],dp[i+1][j+1],dp[i+1][j-1]);
49             }
50         }
51         printf("%d\n",dp[0][5]);
52     }
53     return 0;
54 }

 

posted @ 2012-07-12 21:32  _雨  阅读(222)  评论(0编辑  收藏  举报