hdu acm 1028 数字拆分Ignatius and the Princess III
Ignatius and the Princess III
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11810 Accepted Submission(s): 8362
"The second problem is, given an positive integer N, we define an equation like this:
N=a[1]+a[2]+a[3]+...+a[m];
a[i]>0,1<=m<=N;
My question is how many different equations you can find for a given N.
For example, assume N is 4, we can find:
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
so the result is 5 when N is 4. Note that "4 = 3 + 1" and "4 = 1 + 3" is the same in this problem. Now, you do it!"
最简单的母函数模板题,用于学习和回顾母函数非常方便,代码也可直接做模板使用
/*
hdu acm 1028 数字拆分,母函数模板题
by zhh
*/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cstring> using namespace std;
#define maxx 120
int ans[maxx+],temp[maxx+];
void init()//母函数打表
{
for(int i=;i<=maxx;i++)//初始化第一个式子系数
{
ans[i]=;
temp[i]=;//用于临时保存每次相乘的结果
}
for(int i=;i<=maxx;i++)//循环每一个式子
{
for(int j=;j<=maxx;j++)//循环第一个式子各项
for(int k=;k+j<=maxx;k+=i)//下个式子的各项
temp[k+j]+=ans[j];//结果保存到temp数组中
for(int j=;j<=maxx;j++)//临时保存的值存入ans数组
{
ans[j]=temp[j];
temp[j]=;
}
}
}
int main()
{
init();
int n;
while(scanf("%d",&n)!=EOF)
{
cout<<ans[n]<<endl;
}
return ;
}
hdu acm 1028 数字拆分Ignatius and the Princess III的更多相关文章
- ACM学习历程—HDU1028 Ignatius and the Princess III(递推 || 母函数)
Description "Well, it seems the first problem is too easy. I will let you know how foolish you ...
- Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数
Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...
- 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 整数的划分问题(打表或者记忆化搜索)
传送门: 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
题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...
- 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(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 Sample Ignatius and the Princess III (母函数)
Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
随机推荐
- What is “:-!!” in C code?
stackoverflow上看到的这个问题,觉得挺有趣,顺手记下来. 楼主提问: I bumped into this strange macro code in /usr/include/linux ...
- SQL联合查询两个表的数据
刚有个项目,需要查询水位数据表中的水位信息,及查询降雨量表中统计时段降雨量的数据,以计算出日降雨量,而且时段是前一天8时到后一天8时总共24个小时. 两个子查询: 1.根据当前时间判断统计前天8时到今 ...
- MySql索引简介
从"找"到B+树 索引是用来查找的. 折半查找是一种很优秀的方式.适合于 范围查找,固有缺点就是需要元素是有序的.二叉搜索树就是对折半查找的一种基础的实现. 但二叉搜索树当遇到特殊 ...
- linux配置java环境变量(详细)
linux配置java环境变量(详细) 本文完全引用自: http://www.cnblogs.com/samcn/archive/2011/03/16/1986248.html 一. 解压安装jdk ...
- JS浮点数的加减乘除运算
文章来源地址:http://blog.csdn.net/lyd518/article/details/7236464 转载请注明出处,尊重作者劳动成果,谢谢!问题这样的: 37.5*5.5=206.0 ...
- 脚本录制(JMeter)
使用JMeter录制脚本: 1.打开JMeter工具,创建一个线程组,接着创建一个http代理服务器,代理服务器设置如下:
- SQLserver聚集表、堆和索引
SQL Server 表使用下列两种方法之一来组织其分区中的数据页: 聚集表是有聚集索引的表.数据行基于聚集索引键按顺序存储.聚集索引按 B 树索引结构实现,B 树索引结构支持基于聚集索引键值对行进行 ...
- html5 录制mp3音频,支持采样率和比特率设置
13年的时候做过html5录音,一个问题是保存的wav格式文件很大,当初用了一个迂回的方式,上传到服务器后调用 lame 编码器转换,但由于文件大,上传较慢.不得不说,前端技术发展真是日新月异,有人实 ...
- oracle 体系结构
oracle 体系结构 数据库的体系结构是指数据库的组成.工作过程与原理,以及数据在数据库中的组织与管理机制. 1. oracle工作原理: 1).在数据库服务器上启动Oracle实例:2).应用程序 ...
- XE3随笔16:将字符串转换成 UTF8 编码的函数
这种转换一般用于网页地址; 我不知道 Delphi 是不是有现成的函数, 用到了就写了一个. //函数: function ToUTF8Encode(str: string): string; var ...