hdu-4615 Partition

9 篇文章 0 订阅
3 篇文章 0 订阅

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

题目大意就是整数拆分

数据特别大,不能用以前的递归

所以。。。  不能百度  只能谷歌抓狂 http://en.wikipedia.org/wiki/Partition_%28number_theory%29

然后在里面找一个公式

Leonhard Euler's pentagonal number theorem implies the identity

p(n)=p(n-1)+p(n-2)-p(n-5)-p(n-7)+\cdots

p(n)=\sum_k (-1)^{k-1}p\left(n- k(3k -1)/2\right)

where the summation is over all nonzero integers k (positive and negative) and p(m) is taken to be 0 if m < 0.

但这个公式不完全,然后自己推理,再加小小的DP,就有代码了,

代码如下:

#include <iostream>
#include <cstdio>
#define MAX 100000+10
#define MOD 1000000007
using namespace std;
int  f[MAX];
void init()
{
    for(int i=3; i<=100000; i++)
    {
        f[i]=0;
        for(int j=1; j*(3*j-1)/2 <=i; j++)
        {
            if(j%2==0)
            {
                f[i]=(f[i]-f[i-j*(3*j-1)/2]+MOD)%MOD;
                if((i-j*(3*j-1)/2-j)>=0)
                    f[i]=(f[i]-f[i-j*(3*j-1)/2-j]+MOD)%MOD;
            }
            else
            {
                f[i]= (f[i]+f[i-j*(3*j-1)/2])%MOD;
                if((i-j*(3*j-1)/2-j)>=0)
                    f[i]=(f[i]+f[i-j*(3*j-1)/2-j])%MOD;
            }
        }
    }
}
int main()
{
    int T;
    f[0]=1;f[1]=1;f[2]=2;
    init();
    scanf("%d",&T);
    while(T--)
    {

        int n;
        scanf("%d",&n);
        printf("%d\n",f[n]);
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值