杭电1028Ignatius and the Princess III

View Code
 1 //杭电1028Ignatius and the Princess III
 2 /*
 3  4 = 4;
 4  4 = 3 + 1;
 5  4 = 2 + 2;
 6  4 = 2 + 1 + 1;
 7  4 = 1 + 1 + 1 + 1;
 8 
 9 Sample Input
10 4
11 10
12 20
13  
14 
15 Sample Output
16 5
17 42
18 627
19 */
20 #include<stdio.h>
21 int num[121][121] = {0};
22 int q(int m,int n)
23 {
24     if(m == 0)m = 1;
25     if(n > m)n = m;
26     if(num[m][n] == 0)
27     {
28         num[m][n] = q(m,n-1) + q(m-n,n);
29     }
30     return num[m][n];
31 }
32 
33 int main()
34 {
35     int m;
36     for(int i = 1;i < 121;i++)
37     {
38         num[1][i] = 1;
39         num[i][1] = 1;
40     }
41     while(scanf("%d",&m)!=-1)
42     {
43         printf("%d\n",q(m,m));
44     }
45     return 0;
46 }

 

posted @ 2012-07-13 19:21  zlyblog  阅读(193)  评论(0编辑  收藏  举报