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 ...
随机推荐
- 1 producer — n consumers 模型 实现
#include<stdio.h> #include<string.h> #include<pthread.h> #include<stdlib.h> ...
- .NET中常见的加解密方式
在互联网普及的初期,人们更关注单纯的连接性,以不受任何限制地建立互联网为最终目的.正如事情都具有两面性,互联网的便捷性给人们带来了负面问题,计算机病毒的侵害.信息泄露.网络欺诈等利用互联网的犯罪行为日 ...
- loj2002 「SDOI2017」序列计数
水题 #include <iostream> #include <cstring> #include <cstdio> using namespace std; t ...
- centos 修改时间 计划任务
centos 修改时间 计划任务 一,系统时间修改 1 远程连接到centos 或者直接登录系统 #date 查看系统时间 如下图所示 2 #date -s 修改时间 看下面的例子#date -s ...
- vim使用技巧二 模式
第一部分模式 第2章 普通模式 打开vim的默认状态即为普通模式 普通模式的命令强大 很大程度源于可以把操作符与动作命令结合在一起 技巧7 停顿时请移开画笔 工欲善其事,必先利其器 准 ...
- .NET重构(四):窗体继承+模板方法,完美实现组合查询
导读:在机房重构中,有好些个查询都是大同小异,最为显著的就是组合查询了.怎样给自己省事儿,相同的东西能不能重复利用,就成了一个现实的问题.第一遍做机房的时候,使用的更多的是:复制+粘贴.学习了设计模式 ...
- iOS代理转移
在控制器里面想调用一个视图的子视图的代理方法很简单 1.找到子视图的协议和代理属性 2.给你想调用的控件添加代理属性,遵守的协议和子视图的一样 3.重写代理属性的set方法
- nginx进程属主问题讨论
文章作者:luxianghao 文章来源:http://www.cnblogs.com/luxianghao/p/6107096.html 转载请注明,谢谢合作. 免责声明:文章内容仅代表个人观点,如 ...
- PC端有什么好用的倍速播放的软件?
倍速播放的目的是让自己可以以更快的速度去看视频, 加快获取信息的效率 potplay吧,和KMP是一个作者.加速播放快捷键是c,减速时x,z恢复正常.下载官网 Global Potplayer
- 【二叉树】hdu 1710 Binary Tree Traversals
acm.hdu.edu.cn/showproblem.php?pid=1710 [题意] 给定一棵二叉树的前序遍历和中序遍历,输出后序遍历 [思路] 根据前序遍历和中序遍历递归建树,再后续遍历输出 m ...