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 ...
随机推荐
- debian 中的jdk
1 openjdk 2 debian安装java的脚本 3 下载bin自己编译
- python基础-对象
1. 对象:一组数据和操作数据方法的集合 >>> class Person(object): ... def __init__(self,name): ... ...
- 图论trainning-part-1 B. A Walk Through the Forest
B. A Walk Through the Forest Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO format: %I64 ...
- conda管理包
清理 conda clean --lock --tarball --package (安装包) 安装或更新包 conda install numpy=1.9.3 conda update numpy= ...
- Flask+ Angularjs 实例: 创建博客
允许任何用户注册 允许注册的用户登录 允许登录的用户创建博客 允许在首页展示博客 允许登录的用户退 后端 Flask-RESTful - Flask 的 RESTful 扩展 Flask-SQLAlc ...
- Laya Timer原理 & 源码解析
Laya Timer原理 & 源码解析 @author ixenos 2019-03-18 16:26:38 一.原理 1.将所有Handler注册到池中 1.普通Handler在handle ...
- shell的case-esac
case ... esac 与其他语言中的 switch ... case 语句类似,是一种多分枝选择结构. case 语句匹配一个值或一个模式,如果匹配成功,执行相匹配的命令.case语句格式如下: ...
- CocoaAsyncSocket一个第三方Socket库
github地址:https://github.com/robbiehanson/CocoaAsyncSocket github上的不完整,cocochina也有demohttp://code4app ...
- 【边双连通】poj 3352 Road Construction
http://poj.org/problem?id=3352 [题意] 给定一个连通的无向图,求最少加多少条边使得这个图变成边双连通图 [AC] //#include<bits/stdc++.h ...
- [暑假集训--数位dp]hdu3652 B-number
A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- ...