Partition

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 462    Accepted Submission(s): 262

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
 
Recommend
zhuyuanchen520
 

欧拉函数的倒数是分割函数母函数,亦即:

生成函数

   (1)

利用五边形数定理可得到以下的展开式:

 (2)
将(2)式带入(1)式,并乘到(1)式的左边,进行展开,合并同类项,根据非常数项的系数为0!!
 
即将生成函数配合五边形数定理,可以得到以下的递归关系式
 #include<stdio.h>
typedef long long ll;
const int mo=;
ll p[];
void pre()//打表,欧拉函数的倒数是分割函数的母函数!!!
{
p[]=;
for(ll i=;i<=;i++)
{
ll t=,ans=,kk=;
while()
{
ll tmp1,tmp2;
tmp1=(*kk*kk-kk)/;
tmp2=(*kk*kk+kk)/;
if(tmp1>i)break;
ans=(ans+t*p[i-tmp1]+mo)%mo;
if(tmp2>i)break;
ans=(ans+t*p[i-tmp2]+mo)%mo;
t=-t;
kk++;
}
p[i]=ans;
}
}
int main()
{
pre();
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
printf("%lld\n",p[n]);
}
}

hdu 4651 Partition(整数拆分+五边形数)的更多相关文章

  1. HDU 4651 Partition 整数划分,可重复情况

    Partition Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. HDU 4651 Partition(整数拆分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4651 题意:给出n.求其整数拆分的方案数. i64 f[N]; void init(){    f[0 ...

  3. hdu 4651 Partition (利用五边形定理求解切割数)

    下面内容摘自维基百科: 五边形数定理[编辑] 五边形数定理是一个由欧拉发现的数学定理,描写叙述欧拉函数展开式的特性[1] [2].欧拉函数的展开式例如以下: 亦即 欧拉函数展开后,有些次方项被消去,仅 ...

  4. hdu - 4651 - Partition

    题意:把一个整数N(1 <= N <= 100000)拆分不超过N的正整数相加,有多少种拆法. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid ...

  5. HDU-4651 Partition 整数拆分,递推

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4651 题意:求n的整数拆为Σ i 的个数. 一般的递归做法,或者生成函数做法肯定会超时的... 然后要 ...

  6. hdu 4651 Partition && hdu 4658 Integer Partition——拆分数与五边形定理

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4651 参考:https://blog.csdn.net/u013007900/article/detail ...

  7. hdu 4651 - Partition(五边形数定理)

    定理详见维基百科....http://zh.wikipedia.org/wiki/%E4%BA%94%E9%82%8A%E5%BD%A2%E6%95%B8%E5%AE%9A%E7%90%86 代码如下 ...

  8. HDU 4651 (生成函数)

    HDU 4651 Partition Problem : n的整数划分方案数.(n <= 100008) Solution : 参考资料: 五角数 欧拉函数 五边形数定理 整数划分 一份详细的题 ...

  9. 【hdu 4658】Integer Partition (无序分拆数、五边形数定理)

    hdu 4658 Integer Partition 题意 n分拆成若干个正整数的和,每个正整数出现小于k次,分拆方案有多少.(t<=100,n<=1e5) 题解 之前写过一篇Partit ...

随机推荐

  1. fengmiantu3

  2. anaconda 下载包速度慢

    更新清华镜像资源 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda ...

  3. 图解SQLSERVER联合查询和连接查询的区别

      相信很多人都会用SQLSERVER联合查询和连接查询,但是用起来不一定都得心应手,对于其中的原理可能就模糊不清了,要想很牢固地掌握和运用SQL联合查询和连接查询机制,必须对其根本原理有很清晰认识, ...

  4. db2查看当前用户模式及当前用户的权限

    1.连接数据库:db2 connect to appdb 2.查询当前用户模式:select current schema from sysibm.sysdummy1 或 select current ...

  5. BUFFER CACHE和SHARED POOL原理

    http://blog.csdn.net/wanghai__/article/details/4881492 Buffer Cache LRU与Dirty List 在Buffer Cache中,Or ...

  6. mycat 配置简介

    最近在看 mycat ,官网: http://www.mycat.io/  上面就有 PDF 的教程下载.但是对于我这个初学者来讲,搭建环境的时候还是有点晕,下面从一个简单的例子来讲解相关配置.我用的 ...

  7. 职位-CFO:CFO

    ylbtech-职位-CFO:CFO 首席财务官——CFO(Chief Finance Officer)是企业治理结构发展到一个新阶段的必然产物.没有首席财务官的治理结构不是现代意义上完善的治理结构. ...

  8. Firefox,Chrome使用

    Firefox 插件 REDIRECTOR Automatically redirect pages based on user-defined rules. 根据用户定义的规则自动重定向页面的插件. ...

  9. sorted()与sort()函数

    1 sorted可以对series,ndarry,list类型进行排序 默认会从小到大进行排序 arr1 = np.array([1,2,3,4,44,3243,43,8678]) print(sor ...

  10. AlertManager警报通知 E-mail 微信 模板

    # AlertManager警报通知 E-mail 微信 模板 #AlertManager配置 #alertmanager.yml # 全局配置项 global: resolve_timeout: 5 ...