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 (Java/Others)
Problem Description
"Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says.
"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!"
Input
The input contains several test cases. Each test case contains a positive integer N(1<=N<=120) which is mentioned above. The input is terminated by the end of file.
Output
For each test case, you have to output a line contains an integer P which indicate the different equations you have found.
Sample Input
4
10
20
Sample Output
5
42
627
::简单的DP题
代码:
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- typedef long long ll;
- ll dp[125]={1,0};
- int main()
- {
- ios::sync_with_stdio(0);
- for(int i=1; i<=120 ; i++ )//当只有不大于i的数
- for(int j =i ; j<=120 ; j++ )
- dp[j] += dp[j-i];
- int n;
- while(cin>>n)
- cout<<dp[n]<<endl;
- return 0;
- }
hdu 1028 Ignatius and the Princess III(DP)的更多相关文章
- HDU 1028 Ignatius and the Princess III dp整数划分
http://acm.hdu.edu.cn/showproblem.php?pid=1028 dp[i][j]表示数值为i,然后最小拆分的那个数是j的时候的总和. 1 = 1 2 = 1 + 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 整数的划分问题(打表或者记忆化搜索)
传送门: 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 (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 母函数
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 ...
随机推荐
- meta元素常用属性整理
感谢菜鸟教程 参考资料:http://www.runoob.com/w3cnote/meta.html
- 与众不同 windows phone (34) - 8.0 新的控件: LongListSelector
[源码下载] 与众不同 windows phone (34) - 8.0 新的控件: LongListSelector 作者:webabcd 介绍与众不同 windows phone 8.0 之 新的 ...
- oracle client ORA-12541: TNS: 无监听程序
1. Question description: if you are setting the oracle client to add a local network service, you m ...
- SSM框架整合总结
关于ssm整合的相关总结: 1.持久层--->mybatis:通过Spring 来管理持久层的 Mapper (相当于 dao 接口),来完成对数据库的操作. 首先我们回顾一下,在单独使用myb ...
- ahjesus约束方法或属性的调用方
class Program { static void Main(string[] args) { test(); run(); Console.ReadKey(); } static void ru ...
- mvc与三层结构终极区别
http://blog.csdn.net/csh624366188/article/details/7183872 http://www.cnblogs.com/zhhh/archive/2011/0 ...
- [Architecture Pattern] Factory Builder
[Architecture Pattern] Factory Builder 目的 同时提供延迟注入对象.挂载注入项目这两个功能 情景 在开发系统时,如果需要在运行时间才生成并注入对象,可以套用Fac ...
- JSP利用freemarker生成基于word模板的word文档
利用freemarker生成基于word模板的word文档 freemarker简介 FreeMarker是一个用Java语言编写的模板引擎,它基于模板来生成文本输出.FreeMarker与Web容器 ...
- Atitit.病毒木马程序的感染 传播扩散 原理
Atitit.病毒木马程序的感染 传播扩散 原理 1. 从木马的发展史考虑,木马可以分为四代 1 2. 木马有两大类,远程控制 vs 自我复制传播1 3. 自我复制2 3.1. 需要知道当前cpu ...
- 换SSD硬盘,重装系统,一阵子忙乱
许久没重装过系统了,低声下气地问老板要了一块SSD硬盘,不马上安装上手痒得难受,但年底这个时候重装系统绝对忙乱,差点耽误了一份申请表和一份培训记录表. SSD安装:先从网上找相关贴子,最主要的一个 ...