• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

HDU 4651 Partition

qi=((3*i*i)+i)/2

qi=((3*i*i) -i)/2

每个i下面加或减2次

p(n) = \sum_i (-1)^{i-1} p(n-q_i)

 

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.
 

 

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
2013 Multi-University Training Contest 5
 

 

Recommend
zhuyuanchen520
 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 }
View Code 2013-10-25 13:44:44 
posted @ 2013-10-24 23:56  HaibaraAi  阅读(118)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3