hdu_4651_Partition(公式)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4651

题意:给你一个数n,让你输出将n拆分的方案数。

题解:公式题,不解释,当模版记住就行

 1 #include <cstdio>
 2 #include <cstring>
 3 #define LL long long
 4 const LL mod=1000000007;
 5 LL p[100010];
 6 void init(){
 7     p[0]=p[1]=1,p[2]=2,p[3]=3;
 8     for(int i=4; i<=100000;i++){
 9         int fg=1;p[i]=0;
10         for(int j=1;; ++j){
11             int a=(j*j*3+j)/2,b=(j*j*3-j)/2;
12             if(b>i&&a>i)break;
13             if(a<=i)p[i]=(p[i]+p[i-a]*fg+mod)%mod;
14             if(b<=i)p[i]=(p[i]+p[i-b]*fg+mod)%mod;
15             fg=(-1)*fg;
16         }
17     }
18 }
19 int main(){
20     init();
21     int t,n;
22     scanf("%d",&t);
23     while(t--)scanf("%d",&n),printf("%I64d\n",p[n]);
24     return 0;
25 }
View Code

 



 

posted @ 2016-05-18 23:11  bin_gege  阅读(104)  评论(0编辑  收藏  举报