题目链接: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. Mac 安装 Tomcat

    默认mac已经安装好java jdk-----/Library/Java/JavaVirtualMachines 1. http://tomcat.apache.org/download-70.cgi ...

  2. try 返回前执行fianlly

    try catch  finally 语句中 如果try中有返回语句,如果在fianlly代码块中有对这个值修改的话,并不影响其放回值 public class Test { public stati ...

  3. Generate List and Table via ng-repeat

    <div ng-app ng-controller='StudentListController'> <ul> <li ng-repeat='student in stu ...

  4. .Net 自己写个简单的 半 ORM (练手)

    ORM 大家都知道, .Net 是EF  还有一些其他的ORM  从JAVA 中移植过来的 有 , 大神自己写的也有 不管ORM 提供什么附加的 乱七八糟的功能 但是 最主要的 还是 关系映射 的事情 ...

  5. [转载]--用Python 自动安装软件

    脚本使用了  Python 2.3 + Com 对象,所以你的系统必须安装Python2.3或更高版本同时必须安装  Mark Hammond's Win32all 模块 (特别感谢Mark Hamm ...

  6. GNU make 规则

    clean : rm *.tmp 规则格式: targets : prerequisites recipe ... targets : prerequisites : recipe recipe .. ...

  7. Linux ls -l内容详解

    ls -l是列出当前目录下所有文件信息 以下是实例: 具体的文字描述如下: 第1字段:  文件属性字段文件属性字段总共有10个字母组成,第一个字母表示文件类型,如果这个字母是一个减号”-”,则说明该文 ...

  8. spring aop 使用注解方式总结

    spring aop的注解方式:和xml的配置方式略有区别,详细如下: 1.首先还是建立需要的切面类:切面类里面定义好切点配置,以及所有的需要实现的通知方法. /** * */ package com ...

  9. Oracle表结构转换SqlSERVER表结构 脚本

    在审计工作中,有时需要将Oracle的表结构修改后再SqlSERVER中创建表结构,然后将数据导入到SqlSERVER中,在修改表结构的过程中方法狠多.手工修改,最蠢的方法,或者用工具UE批量修改,还 ...

  10. jqgrid 列显示图片

    <script> var img; //自定义图片的格式,可以根据rowdata自定义 function alarmFormatter(cellvalue, options, rowdat ...