Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 14724 Accepted Submission (s): 10371
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
DP[I][J]: The number of methods used to form I in [1,j]
DP[I][J]=DP[I][J-1]+DP[I-J][J]
Because the method of I is not included in the dp[i][j-1]
So take J out alone to ensure that all methods contain at least one J,
i.e. Dp[i-j][j]
#include <map> #include <string> #include <cstring> #include <cstdio> #include <cstdlib># include<cmath> #include <queue> #include <vector> #include <iostream> #include <algorithm > #include <bitset> #include <climits> #include <list> #include <iomanip> #include <stack > #include <set>using namespace std;int dp[200][200];int dfs (int a,int b) {if (dp[a][b]!=-1) return dp[a][b];if (b ==1) return dp[a][b]=1;if (a<b) return Dp[a][b]=dfs (A,a), if (a==b) return Dp[a][b]=dfs (a,b-1) +1;return Dp[a][b]=dfs ( a,b-1) +dfs (a-b,b);} int main () {int N;while (cin>>n) {memset (dp,-1,sizeof (DP)); Cout<<dfs (N,n) <<endl;}}
Hdu1028ignatius and the Princess III