HDU1028 Ignatius and the Princess III 求一个整数被分为多个数相加有多少种可能
此题是一个母函数的问题,母函数到现在我都没弄懂,幸亏看了很多网上大神们的解答,小女子才有点明白~~
源码如下:
1 #include <stdio.h> 2 #include <string.h> 3 4 int main(){ 5 int n; 6 int dp[130][130]; 7 int i,j; 8 9 memset(dp, 0, sizeof(dp)); 10 dp[1][1] = 1; 11 for(i = 1; i <= 130; i++) { 12 dp[i][1] = 1; 13 dp[1][i] = 1; 14 } 15 for(i = 2; i <= 120; i++) { 16 for(j = 2; j <= 120 ; j++){ 17 if(j > i){ 18 dp[i][j] = dp[i][i]; 19 } 20 else if(j == i){ 21 dp[i][j] = dp[i][j-1] + 1; 22 } 23 else{ 24 dp[i][j] = dp[i][j-1] + dp[i-j][j]; 25 } 26 } 27 } 28 while(scanf("%d",&n) != EOF){ 29 printf("%d\n",dp[n][n]); 30 } 31 32 return 0; 33 }
Everything will be ok in the end. If it is not ok then it is not the end.