题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028

题目大意:3=1+1+1=1+2=3 ;4=4=1+1+1+1=1+2+1=1+3;所以3有3种加法,4有4种加法,给出一个n,(1<=n<=120) ,计算n有几种加法。

解法:母函数的最简单的一道入门题之一。

说明:今早上突发奇想着想学学母函数,就搜了搜HDU ACM PPT 的母函数一版,把这道题分享给大家。

感想:这道题之前看过,推过公式什么的,没推出来。今天才知道是母函数的算法。算法果然奇妙啊,我得加紧学习算法了。

 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
int main()
{
int an[],bn[];
int n;
while (cin>>n)
{
for (int i= ;i<=n ;i++) {an[i]= ;bn[i]= ; }
//模拟多项式乘法
for (int i= ;i<=n ;i++) // 从第二个多项式开始枚举
{
for (int j= ;j<=n ;j++)//枚举第一个多项式的系数
{
for (int k= ;k+j<=n ;k+=i) //枚举第i个多项式各项系数
{
bn[j+k] += an[j];
}
}
for (int j= ;j<=n ;j++)
{
an[j]=bn[j];
bn[j]=;
}
}
printf("%d\n",an[n]);
}
return ;
}

hdu 1028 Ignatius and the Princess III的更多相关文章

  1. hdu 1028 Ignatius and the Princess III 简单dp

    题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...

  2. HDU 1028 Ignatius and the Princess III 整数的划分问题(打表或者记忆化搜索)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1028 Ignatius and the Princess III Time Limit: 2000/1 ...

  3. hdu 1028 Ignatius and the Princess III(DP)

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  4. HDU 1028 Ignatius and the Princess III (母函数或者dp,找规律,)

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  5. hdu 1028 Ignatius and the Princess III 母函数

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  6. hdu 1028 Ignatius and the Princess III (n的划分)

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  7. HDU 1028 Ignatius and the Princess III (递归,dp)

    以下引用部分全都来自:http://blog.csdn.net/ice_crazy/article/details/7478802  Ice—Crazy的专栏 分析: HDU 1028 摘: 本题的意 ...

  8. HDU 1028 Ignatius and the Princess III (生成函数/母函数)

    题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...

  9. HDU 1028 Ignatius and the Princess III (动态规划)

    题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...

随机推荐

  1. C# 运行时编辑 节点重命名

    方法一: ; bool nodeChanged = false; //右键点击,就进入修改状态 private void treeView1_NodeMouseClick(object sender, ...

  2. Linux文件系统的主要目录结构说明及分区方案

    Linux操作系统有一些固定的目录.各种Linux发行版的目录结构虽然不会一模一样,但是不会有很大差异.知道了这些目录的作用,不仅对你进行磁盘分区规划很有帮助,而且会让你以后的日常维护工作变得轻松.只 ...

  3. scala实现kmeans算法

    算法的概念不做过都解释,google一下一大把.直接贴上代码,有比较详细的注释了. 主程序: import scala.io.Source import scala.util.Random /** * ...

  4. 第四节:监视AppDomain

    宿主应用程序可监视AppDomain消耗的资源.有的宿主根据这种信息判断一个AppDomain的内存或CPU消耗是否超过了应有的水准,并强制卸载一个AppDomain. 还可以利用监视来比较不同算法的 ...

  5. xm 命令详解

    xm 命令详解 xm addlabel label dom configfile [policy] xm addlabel label res resource [policy] 增加了名称为labe ...

  6. DB2测试存储过程的原子性

    存储过程在运行过程中需要对其做异常处理.原子性等测试 下面是一个原子性测试案例 ===================================== 代码区域 ================= ...

  7. rman 命令

    OS: Oracle Linux Server release 5.7 DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - ...

  8. oracle 各种问题排查

    一.ORA-00257 ORA-00257归档日志写满,最简单方法.可以更改归档的大小. 二.job不自动运行解决方法 http://www.cnblogs.com/xbding/p/5861443. ...

  9. 记录一下mvc发布

    让别人也可以访问你电脑上的ASP.NET MVC创建的网站 http://www.cnblogs.com/laoqi/p/4169184.html

  10. Swift Tips - 当 Swift 遇上 CocoaPods

    CocoaPods 作为 iOS 开发的包管理工具,几乎成为了 Objective-C 的行业标准.它为我们提供了非常方便的包管理功能.而苹果正式发布 Swift 语言也已经有半年多时间了,Swift ...