hdu 1028 Ignatius and the Princess III
题目链接: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的更多相关文章
- hdu 1028 Ignatius and the Princess III 简单dp
题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...
- 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 ...
- 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 ...
- 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 ...
- hdu 1028 Ignatius and the Princess III 母函数
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- 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 ...
- HDU 1028 Ignatius and the Princess III (递归,dp)
以下引用部分全都来自:http://blog.csdn.net/ice_crazy/article/details/7478802 Ice—Crazy的专栏 分析: HDU 1028 摘: 本题的意 ...
- HDU 1028 Ignatius and the Princess III (生成函数/母函数)
题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...
- HDU 1028 Ignatius and the Princess III (动态规划)
题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...
随机推荐
- MongoDb 与 Nodejs服务器的启动
1) 启动MongoDB : MongoDB —dbpath databaseNameFolder. 2) 启动数据库 : Mongo DatabaseName. 3) 启动NodeJs: Node ...
- mysql 修改字段长度
mysql 修改字段长度 alter table news modify column title varchar(130); alter table 表名 modify column 字段名 类型 ...
- Win+R快速打开你的应用程序
参考自:http://blog.csdn.net/nothing0318/article/details/7179405 1:在你的磁盘任意位置创建一个文件夹,比如C:MyShortcut,然后将你的 ...
- windows下文件名非法字符
/ \ : * ? " < > | / \如果用作文件名,会产生路径问题.因为绝对路径用 \ ; 相对路径用 / ;
- Linq的一些记录
1. IQueryable接口与IEnumberable接口的区别: IEnumerable<T> 泛型类在调用自己的SKip 和 Take 等扩展方法之前数据就已经加载在本地内存里了, ...
- jqGrid(2)
jqGrid使用方法: 原文地址:http://blog.csdn.net/y0ungroc/article/details/12008879 1. 下载文件 1. 下载jqGrid的软件包, ...
- Python核心编程--学习笔记--6--序列(下)列表、元组
11 列表 类似于C语言的数组,但是列表可以包含不同类型的任意对象.列表是可变类型. 创建列表——手动赋值.工厂函数: >>> aList = [12, 'abc'] >> ...
- eval和new Function的区别
eval和new Function都可以动态解析和执行字符串.但是它们对解析内容的运行环境判定不同. var a = 'global scope' function b(){ var a = 'loc ...
- C# 将DataTable装换位List<T> 泛型
public List<T> GetList<T>(DataTable dt) where T:new() { List<T> DateLists = new Li ...
- Oracle Study Note : Users and Basic Security
1. view the default user account SQL> select username from dba_users; 2. lock all users and set t ...