Ignatius and the Princess IIITime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 15210 Accepted Submission (s): 10724
Problem Description "Well, it seems the first problem are too easy. I'll let you know how foolish is later. "feng5166 says.
"The second problem is, given an positive integer N, we define a equation like this:
N=A[1]+A[2]+A[3]+...+A[M];
a[i]>0,1<=m<=n;
My question is what many different equations you can find for a given N.
For example, assume N is 4, we can find:
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
The result is 5 while N is 4. Note that "4 = 3 + 1" and "4 = 1 + 3" are the same in this problem. Now, do it! "
Inputthe input contains several test cases. Each test case contains a positive an integer N (1<=n<=120) which is mentioned above. The input is terminated by the end of file.
Outputfor each of the test case and you had to output a line contains an integer P which indicate the different equations you had Found.
Sample Input
41020
Sample Output
542627
Authorignatius.l
Problem solving: Think of N as the number of apples, each position as a plate, then a maximum of n plates. The number of M plates is n/m, that is to say, every apple on a plate the principle of obedience is: Non-incremental release quantity.
#include <stdio.h> #include <string.h>const int N = dp[n][n][n],sum[n][n];int; #define LL __int64ll Main () { memset (dp,0,sizeof (DP)); memset (sum,0,sizeof (sum)); for (int i=1;i<=124;i++) dp[i][1][i]=1; Sum[1][1]=1; for (int i=2;i<=124;i++)//Apple number for (int j=2;j<=i;j++) { //plate number for (int k=0;k<=i/j;k++) {// The number of the last disk put dp[i][j][k]=0; for (int tk=k;tk<= (I-K)/(j-1); tk++)//The number of second-to-last disk set DP[I][J][K]+=DP[I-K][J-1][TK]; SUM[I][J]+=DP[I][J][K]; } } int n; while (scanf ("%d", &n) >0) printf ("%i64d\n", Sum[n][n]);}
Method Two: The source of the method
#include <stdio.h> #include <string.h>const int N = __int64ll, #define LL sum[n][n];int main () { memset (Sum,0,sizeof (sum)); for (int i=1;i<=124;i++) sum[1][i]=sum[i][1]=1; for (int i=2;i<=120;i++) for (int j=2;j<=120;j++) { if (j>i) sum[i][j]=sum[i][i]; else if (i==j) sum[i][j]=sum[i][j-1]+1; else sum[i][j]=sum[i][j-1]+sum[i-j][j]; } int n; while (scanf ("%d", &n) >0) printf ("%i64d\n", Sum[n][n]);}
Hdu1028ignatius and the Princess III (how many combinations of a number, DP) and how many seed combinations are there in the M plates with n apples (two solutions)