hdu 4651 Partition (利用五边形定理求解分割数)
2014-05-08 11:07
387 查看
以下内容摘自维基百科:
五边形数定理[编辑]
五边形数定理是一个由欧拉发现的数学定理,描述欧拉函数展开式的特性[1] [2]。欧拉函数的展开式如下:
亦即
欧拉函数展开后,有些次方项被消去,只留下次方项为1, 2, 5, 7, 12, ...的项次,留下来的次方恰为广义五边形数。
其中符号为- - + + - - + + .....
若将上式视为幂级数,其收敛半径为1,不过若只是当作形式幂级数(formal
power series)来考虑,就不会考虑其收敛半径。
和分割函数的关系
欧拉函数的倒数是分割函数的母函数,亦即:其中
为k的分割函数。
上式配合五边形数定理,可以得到
考虑
项的系数,在
n>0 时,等式右侧的系数均为0,比较等式二侧的系数,可得
因此可得到分割函数p(n)的递归式
以n=10为例
知道这个定理的话,hdu 4651就可以直接套模板了
#include<algorithm> #include<iostream> #include<cstring> #include<vector> #include<cstdio> #include<cmath> #include<queue> #include<stack> #include<map> #include<set> #define MP make_pair #define LL long long #define CLR(a, b) memset(a, b, sizeof(a)) using namespace std; const int maxn = 100100; const int INF = 0x3f3f3f3f; const LL MOD = 1000000007; int fiv[maxn]; LL p[maxn]; void init() { int tot = 1; for(int i = 1; fiv[tot - 1] < maxn; i ++)///五边形数 { fiv[tot ++] = i*(3*i-1)/2; fiv[tot ++] = i*(3*i+1)/2; } p[0] = 1; for(int i = 1; i < maxn; i ++)///i的分割数p(i) { p[i] = 0;int flag = 1; for(int j = 1; ; j ++) { if(fiv[j] <= i) { p[i] += flag * p[i - fiv[j]]; p[i] = (p[i] % MOD + MOD) % MOD; } else break; if(j % 2 == 0) flag = -flag; } } } int main() { int T, n; init(); scanf("%d", &T); while(T --) { scanf("%d", &n); printf("%lld\n", p ); } }
相关文章推荐
- hdu 4651 Partition (利用五边形定理求解切割数)
- hdu 4651 Partition,公式题,维基百科上搜五边形定理即可
- hdu 4651 - Partition(五边形数定理)
- hdu 4651(求整数的组合数,五边形定理)
- hdu - 4651 - Partition(五边形数定理)
- [五边形数定理 DP] 51Nod 1259 整数划分 V2 & HDU 4651 Partition
- hdu 4651 Partition 五边形数定理
- hdu - 4651 - Partition
- HDU 4651 Partition
- HDU 4651 数学 五边形数定理
- 【公式题】HDU 4651—— Partition
- HDU 4651 Partition 整数划分,可重复情况
- HDU - 1573 - X问题(中国剩余定理不满足互质情况下的求解)
- hdu 4651 Partition
- 2013 多校第五场 hdu 4651 Partition
- HDU 4671 - Partition(2013MUTC5-1009)(整数拆分,五边形数定理)
- hdu 4651 Partition
- 利用中国剩余定理加速解密算法求解
- HDU 4651 Partition(整数划分)
- 【五边形定则应用2】HDU 4602——Partition