HDU's ACM 1028 Ignatius and the Princess III
来源:互联网 发布:php环境集成包下载 编辑:程序博客网 时间:2024/06/05 04:40
原题链接:HDU's ACM 1028 Ignatius and the Princess III
分析:此为母函数第一滴血,可参见母函数-Wikipedia。思路是转换为多项式乘法的结果,对应次方的系数表示该次方拆分的方法数,如f(3)=(1+x+x^2+x^3)*(1+x^2)*(1+x^3)=1+x+2x^2+6x^3+2x^4+3x^5+3x^6+x^7+x^8...
注意:可以参阅《程序设计中的组合数学》里面有较为详细的介绍。喜欢的同学可以购买书籍学习。
<span style="font-family:Microsoft YaHei;font-size:14px;">#include <stdio.h>#define MAXN 150int coeff1[MAXN]; // 存储系数,下标指示指数int coeff2[MAXN]; int main(){int n;int i, j, k;while(scanf("%d", &n) == 1) {for(i=0;i<=n;++i){coeff1[i] = 1;coeff2[i] = 0;}for(i=2;i<=n;++i) {for(j=0;j<=n;++j) {for(k=0;j+k<=n;k+=i) {coeff2[j+k] += coeff1[j]; // coeff2做辅助存储使用}}for(j=0;j<=n;++j){coeff1[j] = coeff2[j];// 最终结果存储在coeff1中coeff2[j] = 0;}}printf("%d\n", coeff1[n]);}return 0;}</span>
0 0
- HDU's ACM 1028 Ignatius and the Princess III
- 杭电 HDU ACM 1028 Ignatius and the Princess III
- hdu acm 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 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
- 博客导航
- Eclipse下svn的创建分支/合并/切换使用
- c语言输入输出
- iOS 根据文字长度计算Lable高度
- SpringMVC控制器
- HDU's ACM 1028 Ignatius and the Princess III
- wifi robot的安卓端开发经验教训
- java.lang.ClassNotFoundException: org.apache.log4j.LogManager
- iOS 瀑布流实现
- 如何使用Grunt脚手架快速创建Node.js项目
- 杭电——不容易序列之二
- View的生命周期以及涉及到内存警告的问题
- SVN 分支及合并的介绍和实践
- 【leetcode 二叉树摊直】Flatten Binary Tree to Linked List