Ignatius and the Princess IIITime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 17692 Accepted Submission (s): 12403
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
The main topic: Give an integer n, divide him into 1-n integer, ask how many kinds of combination number;
Problem-solving ideas: The female function, the exponent is a numeric value, is represented by an array subscript, and the coefficient is the scheme number, expressed as the value stored in the array; however, it can also be done with a complete backpack;
The code is as follows:
#include "iostream" #include "Cstdio" #include "CString" using namespace Std;const int maxn = 120;int NUM[MAXN + 1];int C1[MAXN + 1], C2[MAXN + 1];int main () {int n;while (scanf ("%d", &n)! = EOF) {for (int i = 1;i <= n;i + +) num[i] = n/i; memset (c1, 0, sizeof C1); memset (c2, 0, sizeof C2); for (int i = 0;i <= num[1];i + +) C1[i] = 1;for (int i = 2;i <= n;i + +) {//total of 26 polynomial for (int j = 0;j <= Maxn;j + +) {//Total maxn+1 items for (int k = 0;k <= Num[i] && j + k*i <= maxn;k + +) C2[j + k*i] + = C1[j];} for (int j = 0;j <= Maxn;j + +) {C1[j] = c2[j];c2[j] = 0;}} printf ("%d\n", C1[n]);} return 0;}
Ignatius and the Princess III (hdu_1028) female function + integer split