hdu 4651 Partition 多校第五场

来源:互联网 发布:模仿神烦狗doge软件 编辑:程序博客网 时间:2024/05/16 08:51

参见五边形定理。。

点击打开链接


#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <iostream>#include <map>#include <vector>#include <algorithm>#include <set>using namespace std;#define clr(a, x) memset(a, x, sizeof(a))#define rep(i, n) for (int i = 0; i < (int)(n); i++)#define REP(i,a,b) for(int i=a;i<=b;i++)const double pi = 3.1415926;const int mod = 1000000007;const int maxn = 100010;int p[maxn];int P(int k,int i){    int res=0;    if(i-(3*k-1)*k/2>=0) res+=p[i-(3*k-1)*k/2];    if(i-(3*k+1)*k/2>=0) res+=p[i-(3*k+1)*k/2];    res%=mod;    if(k&1) return res;    else return -res;}int main(){    int n;    p[0]=1;    p[1]=1;    p[2]=2;    p[3]=3;    for(int i=4;i<maxn;i++)    {        p[i]=0;        for(int k=1;k<=i;k++)        {            if(i-0.5*(3*k-1)*k<-1) break;            p[i]=(p[i]+P(k,i))%mod;        }        p[i]=(p[i]+mod)%mod;        //printf("i=%d %d\n",i,p[i]);    }    int T;    scanf("%d",&T);    while(T--)    {        scanf("%d",&n);       // int ans=solve(n);        //double ans=1.0/(4.0*n*sqrt(3.0))*exp(pi*sqrt(2.0*n/3));        printf("%d\n",p[n]);    }}//p(n,k) = p(n-1,k-1)+p(n-k,k)