hdu 1028 Ignatius and the Princess III 母函数
2013-07-24 10:40
513 查看
题意是 求数字n 可以拆成多少种不同的等式,等式中顺序不计。
这种无序的组合方式用母函数解决,如果是有序的话就用组合计数可可以求得一个公式 2^(n-1).
这个问题可以转化成这样一个问题:
给出1 到n ,这n种不同的数,每个数可以使用无限次,问有多少种组合方式可以凑出n。这样就转化成了一个简单的母函数问题。
G( x ) = (1 + x^1 + x^2 +x^3 + .....)(1 + x^2 + x^4 +x^6 +.....)( 1+ x^3 +x^6 + x^9 +.....).....(1+x^n + x^2n + x^3n +........)
G(x) 展开式种 x^n 项的 系数 就是所求的结果。
求x^n 的系数 用的是dp的思想。
扩展 : 整数n 拆分成k 个数的和的拆分 ,与 整数n 拆分成最大数为k 的拆分数相同。
整数n 拆分成不超过k个数的和的拆分数,等于讲n+ k 拆分成 恰好k个数的拆分数。
这种无序的组合方式用母函数解决,如果是有序的话就用组合计数可可以求得一个公式 2^(n-1).
这个问题可以转化成这样一个问题:
给出1 到n ,这n种不同的数,每个数可以使用无限次,问有多少种组合方式可以凑出n。这样就转化成了一个简单的母函数问题。
G( x ) = (1 + x^1 + x^2 +x^3 + .....)(1 + x^2 + x^4 +x^6 +.....)( 1+ x^3 +x^6 + x^9 +.....).....(1+x^n + x^2n + x^3n +........)
G(x) 展开式种 x^n 项的 系数 就是所求的结果。
求x^n 的系数 用的是dp的思想。
#include <cstdio> #include <cstring> #include <iostream> using namespace std; int dp[121][121]; int n; void solve(){ memset(dp,0,sizeof(dp)); dp[0][0] =1; for(int i=1;i<=n;i++){ for(int j=0;j<=n;j++){ if(dp[i-1][j]){ for(int k = 0;k<=n;k++){ int d = j + k*i; if(d<=n){ dp[i][d]+=dp[i-1][j]; }else{ break; } } } } } cout << dp <<endl; } int main(){ while(~scanf("%d",&n)){ solve(); } return 0; }
扩展 : 整数n 拆分成k 个数的和的拆分 ,与 整数n 拆分成最大数为k 的拆分数相同。
整数n 拆分成不超过k个数的和的拆分数,等于讲n+ k 拆分成 恰好k个数的拆分数。
相关文章推荐
- hdu 1028 Ignatius and the Princess III(母函数)
- 【HDU 1028】【母函数 整数划分】Ignatius and the Princess III
- HDU 1028 Ignatius and the Princess III (母函数模板)
- HDU 1028-Ignatius and the Princess III(拆分整数-母函数-无限次)
- HDU——1028 Ignatius and the Princess III(母函数)
- HDU 1028 Ignatius and the Princess III (母函数)
- hdu 1028 Ignatius and the Princess III ( 母函数)
- hdu 题目1028 Ignatius and the Princess III(母函数及其应用)
- Ignatius and the Princess III (HDU_1028) 母函数 + 整数拆分
- HDU 1028 Ignatius and the Princess III伊格和公主III(AC代码)母函数
- Ignatius and the Princess III 【HDU--1028-母函数】
- hdu 1028 Ignatius and the Princess III +hdu 1085 Holding Bin-Laden Captive!(母函数)
- hdu-1028 Ignatius and the Princess III 【母函数】
- HDU 1028 Ignatius and the Princess III(母函数)
- HDU 1028Ignatius and the Princess III(母函数模板
- HDU 1028 Ignatius and the Princess III(母函数)
- hdu 1028 Ignatius and the Princess III 母函数/dp
- hdu 1028 Ignatius and the Princess III(母函数)
- hdu 1028 Ignatius and the Princess III(母函数,完全背包)
- HDU 1028 Ignatius and the Princess III 生成函数(母函数)