HDU 1028 Ignatius and the Princess III(母函数)
来源:互联网 发布:javahome的作用 知乎 编辑:程序博客网 时间:2024/06/05 04:49
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1028
题意:给定一个数n,将n拆分成一个或几个不大于n的正整数。是这些正整数的和等于n。求出方案数。
分析:构造母函数G(x)=(1+x+x^2+...+x^n)(1+x^2+x^4+...+x^[(n/2)*2])(1+x^3+x^6+...+x^[(n/3)*3])......(1+x^n),展开后x^n的系数就是所求方案数。
代码:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;typedef long long LL;int main(){int n,i,j,k;LL ans;LL t[130],a[130];while(scanf("%d",&n)!=EOF){ans=0;memset(t,0,sizeof(t));memset(a,0,sizeof(a));a[0]=1; for(i=1;i<=n;i++){for(j=0;j<=n;j++)for(k=0;i*k+j<=n;k++)t[i*k+j]+=a[j];for(j=0;j<=n;j++){a[j]=t[j];t[j]=0;}}printf("%lld\n",a[n]);}return 0;}
0 0
- HDU/HDOJ 1028 母函数 Ignatius and the Princess III
- 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(母函数)
- 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 母函数/dp
- Ignatius and the Princess III 【HDU--1028-母函数】
- 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(母函数)
- cuda+vs2010配置
- fedora/centos7防火墙FirewallD详解
- GC日志分析
- Happy New Year!!
- java之处理对象
- HDU 1028 Ignatius and the Princess III(母函数)
- slf4j教程
- 离梦想很近的地方..
- 你好CSDN
- decompress gzip data from object in memory
- C++ STL 算法:删除算法(3)unique、unique_copy
- EXTJS使用XType来定义组件及使用方法
- Leetcode_128_Longest Consecutive Sequence
- 动态模板道指令