【HDOJ】1028 Ignatius and the Princess III

DP问题,二维。

 1 #include <stdio.h>
 2 
 3 #define MAXNUM 125
 4 int dp[MAXNUM][MAXNUM] = {0};
 5 
 6 int main() {
 7     int n, i, j;
 8 
 9     for (i=1; i<MAXNUM; ++i)
10         dp[1][i]= dp[i][1] = 1;
11 
12     for (i=2; i<MAXNUM; ++i)
13         for(j=2; j<MAXNUM; ++j)
14         {
15             if (i==j)
16                 dp[i][j] = dp[i][j-1] + 1;
17             if (i>j)
18                 dp[i][j] = dp[i-j][j] + dp[i][j-1];
19             if (i<j)
20                 dp[i][j] = dp[i][i];
21         }
22     while (scanf("%d",&n) != EOF)
23         printf("%d\n", dp[n][n]);
24 
25     return 0;
26 }
View Code

 

posted on 2014-03-18 22:30  Bombe  阅读(112)  评论(0编辑  收藏  举报

导航