HDU -- 1028 Ignatius and the Princess III(母函数)
来源:互联网 发布:算法之美 京东 编辑:程序博客网 时间:2024/05/19 13:17
题目大意:给定一个n,求它有几种构成方式;
例如4 :4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
一共是5种;
思路分析:构造母函数:(1+x+x^2+x^3...+x^n)(1+x^2+x^4+...)(1+x^3+x^6+...)...(1+x^n);
对于第一个式子(1+x+x^2+x^3...+x^n):我们可以理解为分别用了0个1,1个1,2个1,...,n个1能构成的数;
对于第二个式子(1+x^2+x^4+...):我们可以理解为分别用了0个2,1个2,2个2....能构成的数;
那么第一个式子乘第二个式子就代表了用1和2分别能构成那些数,其展开的系数就是用1和2能够成的数的构成方案数;
...
代码实现:
#include<stdio.h>const int maxn=130;int c1[maxn],c2[maxn];int main(){ int n; while(scanf("%d",&n)!=EOF){ for(int i=0;i<=n;i++){ c1[i]=1;//相当于初始第一个式子的系数; c2[i]=0;//用来临时存每一次乘一个式子的情况; } for(int i=2;i<=n;i++){//从第二个式子开始乘,其实控制的是总体的式子范围,一共n个,减去第一个式子; for(int j=0;j<=n;j++){//控制每一个式子; for(int k=0;k+j<=n;k+=i)//控制每个系数的变化和每个数出现的最大项; c2[j+k]+=c1[j]; } for(int j=0;j<=n;j++){ c1[j]=c2[j]; c2[j]=0; } } printf("%d\n",c1[n]); } return 0;}
0 0
- 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(母函数)
- HDU 1028 Ignatius and the Princess III(母函数)
- HDU/HDOJ 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-母函数】
- C 矩阵变化
- 限制玻尔兹曼机(Restricted Boltzmann Machine)学习笔记(二)
- 操作系统概论——整体把握
- 【电脑右键打开方式出现没有程序与之相关联】
- MFC笔记
- HDU -- 1028 Ignatius and the Princess III(母函数)
- 【ping命令的用法大全!】
- vc++调试---利用PDB和dump文件定位问题并进行调试(VS2010)
- 2015-2-8-工作日志-刘婉
- Unity3D基础教程】(四):通过制作Flappy Bird了解Native 2D...
- 动态规划(DP)算法
- 任意瀏覽器任意操作系統的跨域+管理員權限運行本地程序
- lua中调用C
- Drop goldengate用户时报ORA-00604 ORA-20782 ORA-06512问题解决