Partition
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 880 Accepted Submission(s): 502
Problem Description
How many ways can the numbers 1 to 15 be added together to make 15? The technical term for what you are asking is the "number of partition" which is often called P(n). A partition of n is a collection of positive integers (not necessarily distinct) whose sum
equals n.
equals n.
Now, I will give you a number n, and please tell me P(n) mod 1000000007.
Input
The first line contains a number T(1 ≤ T ≤ 100), which is the number of the case number. The next T lines, each line contains a number n(1 ≤ n ≤ 105) you need to consider.
Output
For each n, output P(n) in a single line.
Sample Input
4 5 11 15 19
Sample Output
7 56 176 490
Source
Recommend
zhuyuanchen520 | We have carefully selected several similar problems for you: 5141 5140 5139 5138 5137
ac代码
#include<stdio.h> #include<string.h> #define mod 1000000007 __int64 p[100005]; void fun() { int a,b,i,flag=1,j; p[0]=p[1]=1; p[2]=2; p[3]=3; for(i=4;i<100005;i++) { p[i]=0; flag=1; for(j=1;;j++) { a=(j*j*3+j)/2; b=(j*j*3-j)/2; if(a>i&&b>i) break; if(a<=i) p[i]=(p[i]+p[i-a]*flag+mod)%mod; if(b<=i) p[i]=(p[i]+p[i-b]*flag+mod)%mod; flag=-flag; } } } int main() { int t; fun(); scanf("%d",&t); while(t--) { int n; scanf("%d",&n); printf("%I64d\n",p[n]); } }