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 ...
随机推荐
- C#访问配置文件
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...
- 修改 WordPress 文件上传目录
WordPress 默认的上传目录位于 wp-content/uploads ,并且根据设置还可以按照年月归档.但是如果要上传一个头像,或者幻灯片的话,也跟附件混在一起总是不太好吧?幸好 WordPr ...
- Python pass 语句使用示例
Python pass 语句的使用方法示例.Python pass是空语句,pass语句什么也不做,一般作为占位符或者创建占位程序,是为了保持程序结构的完整性,pass语句不会执行任何操作,比如: P ...
- js控制文本框只能输入数字 及 常用字符对应ASCII码值
方法一: <INPUT TYPE='text' NAME=text onkeypress="a()"><script language=javascript> ...
- STM32F0xx_TIM输入捕获(计算频率)配置详细过程
前言 关于STM32的定时器,可谓是功能强大,估计没有多少人研究完STM32定时器的所有功能(包括我也没有),只是使用常用的一些功能,后续我会推出关于STM32定时器的更多功能. STM32芯片多数为 ...
- [terry笔记]更改oracle用户名
更改oracle的用户名 之前有个需求,整理一个schema的表.索引等规划到一个表空间里,利用expdp/impdp然后remap就完成了,但是整理好的用户名remap变更了,应用又不想修改其连接信 ...
- [转]Posix-- 互斥锁 条件变量 信号量
这是一个关于Posix线程编程的专栏.作者在阐明概念的基础上,将向您详细讲述Posix线程库API.本文是第三篇将向您讲述线程同步. 互斥锁 尽管在Posix Thread中同样可以使用IPC的信号量 ...
- 【javascript】随手记代码
//js实现的当前界面的刷新.前进.后退 <input type="button" value="刷新" onclick="window.loc ...
- ListView用法及加载数据时的闪烁问题和加载数据过慢问题
ListView介绍及添加数据时的闪烁问题 1. ListView类 1.1 ListView常用的基本属性: (1)FullRowSelect:设置是否行选择模式.(默认为false) 提示 ...
- R中统计量的中英文解释
Intercept————截距 formula————公式 Residual standard error残差标准差: 1.319 on 10 degrees of freedom 自由度为10 ...