HDU 4651 Partition
qi=((3*i*i)+i)/2
qi=((3*i*i) -i)/2
每个i下面加或减2次
Partition
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 746 Accepted Submission(s):
438
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.
Now, I will give you a number n, and please tell me P(n) mod 1000000007.
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
View Code 2013-10-25 13:44:44
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include <map> 3 #include <queue> 4 #include <vector> 5 #include <string> 6 #include <cstdio> 7 #include <cstring> 8 #include <iostream> 9 #include <algorithm> 10 using namespace std; 11 #define maxn 100005 12 #define mod 1000000007 13 #define ll long long 14 #define INF 0x7fffffff 15 int n, m, s; 16 ll f[maxn]; 17 void init(){ 18 int s = 1; 19 f[0] = 1; 20 for (int i = 1; i <= 100000; i++){ 21 ll s = 0; 22 for (int j=1,k = 1,flag=1;j>0; k++,flag=-flag){ 23 j = i - (3 * k*k - k) / 2; 24 if (j >= 0)s = (s + (flag*f[j]+mod)%mod) % mod; 25 j = i - (3 * k*k + k) / 2; 26 if (j >= 0)s = (s + (flag*f[j]+mod)%mod) % mod; 27 } 28 f[i] = s; 29 } 30 } 31 int main(){ 32 int cas = 1; 33 int t; 34 init(); 35 scanf("%d", &t); 36 while (t--){ 37 scanf("%d", &n); 38 printf("%d\n", f[n]); 39 } 40 /*while (~scanf("%d", &n)){ 41 printf("%I64d\n", f[n]); 42 }*/ 43 return 0; 44 }

浙公网安备 33010602011771号