Partition

Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 954 Accepted Submission(s): 545
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


题意:问一个数n能被拆分成多少种方法

首先你要知道母函数+然后你要知道五边形数定理;

设第n个五边形数为,那么,即序列为:1,
5, 12, 22, 35, 51, 70, ...

相应图形例如以下:

设五边形数的生成函数为。那么有:

以上是五边形数的情况。以下是关于五边形数定理的内容:

五边形数定理是一个由欧拉发现的数学定理。描写叙述欧拉函数展开式的特性。欧拉函数的展开式例如以下:

欧拉函数展开后,有些次方项被消去。仅仅留下次方项为1, 2, 5, 7, 12, ...的项次,留下来的次方恰为广义五边形数。

五边形数和切割函数的关系

欧拉函数的倒数是切割函数的母函数。亦即:

   当中为k的切割函数。

上式配合五边形数定理,有:

 
在 n>0 时,等式右側的系数均为0,比較等式二側的系数,可得
 

因此可得到切割函数p(n)的递归式:

比如n=10时,有:

所以,通过上面递归式,我们能够非常高速地计算n的整数划分方案数p(n)了。

详见维基百科:https://zh.wikipedia.org/wiki/%E4%BA%94%E8%A7%92%E6%95%B0#.E5.BB.A3.E7.BE.A9.E4.BA.94.E9.82.8A.E5.BD.A2.E6.95.B8 或 https://zh.wikipedia.org/wiki/%E4%BA%94%E9%82%8A%E5%BD%A2%E6%95%B8%E5%AE%9A%E7%90%86 


转载请注明出处:http://blog.csdn.net/u010579068 


详见代码:
#include<iostream>
#include<cstdio>
#define NN 100005
#define LL __int64
#define mod 1000000007 using namespace std;
LL wu[NN],pa[NN];
void init()
{
pa[0]=1;
pa[1]=1;
pa[2]=2;
pa[3]=3;
LL ca=0;
for(LL i=1;i<=100000/2;i++)
{
wu[ca++]=i*(3*i-1)/2;
wu[ca++]=i*(3*i+1)/2;
if(wu[ca-1]>100000) break;
}
for(LL i=4;i<=100000;i++)
{
pa[i]=(pa[i-1]+pa[i-2])%mod;
ca=1;
while(wu[2*ca]<=i)
{
if(ca&1)
{
pa[i]=(pa[i]-pa[i-wu[2*ca]])%mod;
pa[i]=(pa[i]%mod+mod)%mod;
if(wu[2*ca+1]<=i)
pa[i]=(pa[i]-pa[i-wu[2*ca+1]])%mod;
pa[i]=(pa[i]%mod+mod)%mod;
}
else
{
pa[i]=(pa[i]+pa[i-wu[2*ca]])%mod;
pa[i]=(pa[i]%mod+mod)%mod;
if(wu[2*ca+1]<=i)
pa[i]=(pa[i]+pa[i-wu[2*ca+1]])%mod;
pa[i]=(pa[i]%mod+mod)%mod;
}
ca++;
}
}
}
int main()
{
int T,n;
init();
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
printf("%I64d\n",pa[n]);
}
return 0; }




Partition(hdu4651)2013 Multi-University Training Contest 5----(整数拆分一)的更多相关文章

  1. Integer Partition(hdu4658)2013 Multi-University Training Contest 6 整数拆分二

    Integer Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...

  2. Partition(hdu4651)2013 Multi-University Training Contest 5

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

  3. ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków

    ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...

  4. HDU 2018 Multi-University Training Contest 1 Triangle Partition 【YY】

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6300 Triangle Partition Time Limit: 2000/1000 MS (Java ...

  5. HDU 4658 Integer Partition (2013多校6 1004题)

    Integer Partition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. JSU 2013 Summer Individual Ranking Contest - 5

    JSU 2013 Summer Individual Ranking Contest - 5 密码:本套题选题权归JSU所有,需要密码请联系(http://blog.csdn.net/yew1eb). ...

  7. HDU4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)

    Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  8. HDU 2018 Multi-University Training Contest 3 Problem A. Ascending Rating 【单调队列优化】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6319 Problem A. Ascending Rating Time Limit: 10000/500 ...

  9. Ural State University Internal Contest October'2000 Junior Session

    POJ 上的一套水题,哈哈~~~,最后一题很恶心,不想写了~~~ Rope Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7 ...

随机推荐

  1. 自己定义Android Dialog

    private void showDialog() { mDialog = new Dialog(this); mDialog.setCanceledOnTouchOutside(true); Win ...

  2. 具体图解 Flume介绍、安装配置

    写在前面一: 本文总结"Hadoop生态系统"中的当中一员--Apache Flume 写在前面二: 所用软件说明: 一.什么是Apache Flume 官网:Flume is a ...

  3. ubuntu16.04+caffe训练mnist数据集

    1.   caffe-master文件夹权限修改 下载的caffe源码编译的caffe-master文件夹貌似没有写入权限,输入以下命令修改: sudo chmod -R 777 ~/caffe-ma ...

  4. net 线程挂起

    2013.10.18  通讯组件开发 情景: 主线程添加队列,子线程负责队列中消息发送.当队列中数据为空时,停止发送挂起子线程. 当主线程添加队列时,重新开启子线程进行消息发送. 方案一 但是不采用传 ...

  5. Centos7 minimal 系列之NAT联网(一)

    一.安装 参考:http://m.blog.csdn.net/qq_24879495/article/details/77838512 二.解决不能联网问题 打开网络共享中心,设置虚拟网卡 编辑虚拟机 ...

  6. 清北集训Day1T3 LYK loves jumping(期望DP)

    题目描述 LYK在玩一个魔法游戏,叫做跳跃魔法. 有n个点,每个点有两个属性hi和ti,表示初始高度,和下降高度.也就是说,它初始时高度为hi,一旦LYK踩在这个点上,由于重力的影响,这个点的高度会下 ...

  7. 移动端ios升级到11及以上时,手机弹框输入光标出现错位问题

    引起原因:弹框的定位采取position:fixed,而ios(safari)对定位属性position:fixed的解析不一致导致. 解决方案: 方案一 一开始上网找解决方案,找到如下处理方式.但存 ...

  8. Android实现图片相似度

    Android实现图片相似度 最近公司有一个需求,就是希望能判断用户提交的照片是否是身份证的正面或者反面.可以通过预设一张拍摄清晰的身份证正面或者反面,来对比是否相似,那么问题就转化为如何计算两张图片 ...

  9. 关于app夜间模式那点事

    大半年没写过代码了 一直在忙一些其他的事情  这几天想起来看了一点  心惊肉跳的 发现好陌生  所以打算今后慢慢的拾起来  往深度和广度去发展 发现好久之前写的一个微博项目  有一个夜间模式的功能没有 ...

  10. c#将http调用返回额json中的有关中文的unicode转换为中文

    c#将http调用返回额json中的有关中文的unicode转换为中文 中文转Unicode:HttpUtility.UrlEncodeUnicode(string str);转换后中文格式:&quo ...