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)
Total Submission(s): 15942 Accepted Submission(s): 11245
"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 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.
10
20
42
627
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 130
int n,d[N][N];//d[i][j]表示组成不超过j的数组成i有多少种方法 int main()
{
for(int i=;i<=;i++)d[i][]=;
d[][]=;
for(int i=;i<=;i++)
{
for(int j=;j<=i;j++)
{
for(int k=j;k>=;k--)
{
d[i][j]+=d[i-k][min(i-k,k)];
}
}
}
while(~scanf("%d",&n))
{
cout<<d[n][n]<<endl;
}
return ;
}
看了网上的正规dp解法,稍加改进
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 130
int n,d[N][N]; int main()
{
for(int i=;i<=;i++)d[i][]=;
d[][]=;
for(int i=;i<=;i++)
{
for(int j=;j<=i;j++)
{
d[i][j]=d[i][j-]+d[i-j][min(j,i-j)];
}
}
while(~scanf("%d",&n))
{
cout<<d[n][n]<<endl;
}
return ;
}
还有一种母函数的做法
以后再学习
HDU 1028 Ignatius and the Princess III (母函数或者dp,找规律,)的更多相关文章
- 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
题目链接: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 (生成函数/母函数)
题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...
- 题解报告:hdu 1028 Ignatius and the Princess III(母函数or计数DP)
Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...
- 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 ...
随机推荐
- Debian7安装msf
安装metasploit curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templa ...
- Centos7 安装python3详细教程,解决升级后不兼容问题
一.确认当前python版本 [root@centos Python-3.6.1]# python Python 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC ...
- [BZOJ1575] [Usaco2009 Jan]气象牛Baric(DP)
传送门 DP f[i][j]表示前i个中选j个的最优解 预处理g[i][j]表示选i~j对答案的贡献 那么就可以n^3乱搞了! 注意边界 #include <cstdio> #includ ...
- selenium 与 firefox版本不兼容报错
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 ...
- POJ2486 Apple Tree
Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu Description Wshxzt is ...
- Linux设置文件与Shell操作环境
Shell设置文件读取流程 /etc/shells记录了Linux系统中支持的所有shell,默认使用bash.用户登入Linux系统时会获取到一个shell,具体获取到哪个shell与登录账号有关, ...
- spring-boot-nginx代理-docker-compose部署
在本地测试,使用docker部署不用在意环境 java测试项目: web框架:spring boot 框架 项目管理:maven 数据库:redis + postgres + mongo 部署相关:n ...
- sulime text 常用快捷键总结
Sublime Text 3汉化中文版主要特色: -语法高亮.代码提示补全.代码折叠.自定义皮肤/配色方案.多便签 -代码地图.多种界面布局与全屏免打扰模式 -完全开放的用户自定义配置与神奇实用的编辑 ...
- Bruce Eckel:编程生涯
大家总是问一个错误的问题:“我应该学习C++还是Java?”在本文中,我将告诉大伙儿:对于选择编程生涯真正需要关注的是哪些问题. 请注意,这篇文章的目标读者并不是那些已经做出自己选择的人.(对于这些人 ...
- BB FlashBack pro导出AVI格式的配置参数
文件-->导出,选择AVI格式在选择AVI解码器中选择Cinepak Codec by Radius压缩质量:建议6~12%点击确定在AVI导出选项中选择帧速率:4帧每秒音频选择格式 11.02 ...