HDU 4651 数学 五边形数定理
2016-08-03 19:18
344 查看
Partition
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each n, output P(n) in a single line.
[align=left]Sample Input[/align]
4
5
11
15
19
[align=left]Sample Output[/align]
7
56
176
490
题解:五边形数定理
设第n个五边形数为
,那么
,即序列为:1, 5, 12, 22, 35, 51, 70, ... 对应图形如下:
设五边形数的生成函数为
,那么有:
以上是五边形数的情况。下面是关于五边形数定理的内容: 五边形数定理是一个由欧拉发现的数学定理,描述欧拉函数展开式的特性。欧拉函数的展开式如下:
欧拉函数展开后,有些次方项被消去,只留下次方项为1, 2, 5, 7, 12, ...的项次,留下来的次方恰为广义五边形数。 五边形数和分割函数的关系 欧拉函数的倒数是分割函数的母函数,亦即:
其中
为k的分割函数。 上式配合五边形数定理,有:
在 n>0 时,等式右侧的系数均为0,比较等式二侧的系数,可得
因此可得到分割函数p(n)的递归式:
例如n=10时,有:
所以,通过上面递归式,我们可以很快速地计算n的整数划分方案数p(n)了。以上内容转载自http://blog.csdn.net/acdreamers/article/details/12259815
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long ll;
ll dp[100005];
const ll mod=1000000007;
void init(){
ll i,j;
for(i=1;i<=100000;i++){
for(j=1;;j++){
ll k1=j*(3*j-1)/2,k2=j*(3*j+1)/2;
ll signs=j%2?1:-1;
if(k1>i)break;
dp[i]=(dp[i]+signs*(dp[i-k1])+mod)%mod;
if(k2>i)break;
dp[i]=(dp[i]+signs*(dp[i-k2])+mod)%mod;
}
dp[i]=(dp[i]+mod)%mod;
}
}
int main(){
int t;
scanf("%d",&t);
dp[0]=1;
init();
while(t--){
ll n;
scanf("%lld",&n);
printf("%lld\n",dp
);
}
return 0;
}
相关文章推荐
- hdu 4651 Partition 五边形数定理
- hdu 4651 - Partition(五边形数定理)
- [五边形数定理 DP] 51Nod 1259 整数划分 V2 & HDU 4651 Partition
- hdu - 4651 - Partition(五边形数定理)
- 五边形数定理 (hdu 4651 , hdu 4658)
- 【hdu 4658】Integer Partition (无序分拆数、五边形数定理)
- HDU 1796 How many integers can you find [容斥定理] 【组合数学】
- hdu 4135 Co-prime (组合数学:容斥定理+欧拉函数)
- HDU 3903 Trigonometric Function(数学定理)
- hdu 4651 Partition (利用五边形定理求解分割数)
- hdu 4651 Partition (利用五边形定理求解切割数)
- HDU 3903 Trigonometric Function(数学定理)
- HDU 3037 Saving Beans(组合数学+Lucas定理)
- HDU 4671 - Partition(2013MUTC5-1009)(整数拆分,五边形数定理)
- hdu - 1028 - Ignatius and the Princess III(dp / 五边形数定理)
- hdu 4366 Card Collector(组合数学:容斥定理)
- hdu 3037 Saving Beans(组合数学+lucas定理)
- poj 1286 poj 2409 hdu 1812 polya定理 组合数学
- hdu 4651 Partition,公式题,维基百科上搜五边形定理即可
- HDU4651+数学公式