hdu 1208 Ignatius and the Princess III 划分数,dp
题意:给你一个数字n,求将其划分成若干个数字相加总共有多少种划分数;
<span style="font-size:24px;">#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long ll;
typedef unsigned long long ULL;
const int mod = 1000000007;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const int big=50000;
int max(int a,int b) {return a>b?a:b;};
int min(int a,int b) {return a<b?a:b;};
int dp[125][125];
//dp[i][j]=dp[i][j-1]+dp[i-j][j]
int main()
{
memset(dp,0,sizeof(dp));
for(int i=1;i<=120;i++)
for(int j=1;j<=120;j++)
if(j<i)
dp[i][j]=dp[i][j-1]+dp[i-j][j];
else if(j>i)
dp[i][j]=dp[i][i];
else if(i==j)
dp[i][j]=dp[i][j-1]+1;
int n;
while(cin>>n)
cout<<dp[n][n]<<endl;
return 0;
}
</span>
分析:dp;
核心代码:dp[i][j]=dp[i][j-1]+dp[i-j][j]
dp[i][j]代表第i个数划分数中最大不超过j的划分种类数
if(j>i)dp[i][j]=dp[i][i];
如果j==i;dp[i][j]=dp[i][j-1]+1;
if(j<i) dp[i][j]=dp[i][j-1](没有j)+dp[i-j][j](有j,那么取出j,则剩余的划分数中最大也不
能超过j,所以是dp[i-j][j])
hdu 1208 Ignatius and the Princess III 划分数,dp的更多相关文章
- 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:dp or 母函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 题意: 给你一个正整数n,将n拆分成若干个正整数之和,问你有多少种方案. 注:"4 = ...
- 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 (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(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 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 ...
随机推荐
- 【新功能前瞻】SpreadJS 纯前端表格控件V12.2:打印增强、拖拽填充等六大特性
新版本来袭:葡萄城 SpreadJS 纯前端表格控件的全新版本 V12.2 将于8月正式发布! 作为一款备受华为.招商银行.中国平安.苏宁易购等行业专家和前端开发者认可的纯 JavaScript 电子 ...
- 数据结构之二叉树篇卷四 -- 二叉树线索化(With Java)
一.线索二叉树简介 二叉树本身是一种非线性结构,然而当你对二叉树进行遍历时,你会发现遍历结果是一个线性序列.这个序列中的节点存在前驱后继关系.因此,如何将这种前驱后继信息赋予给原本的二叉树呢?这就是二 ...
- java中start()、yield、setDeamon()
本节主要说明以下三个问题 start()的启动顺序不代表线程的启动顺序 yeild的作用 守护线程 1.start()与线程启动顺序 package foreverly.cn.chapter1; pu ...
- jQuery可拖拽旋转的3D图片墙
在线演示 本地下载
- redis 学习(10)-- redis 慢查询
redis 慢查询 什么是慢查询 MySQL会记录下查询超过指定时间的语句,我们将超过指定时间的SQL语句查询称为慢查询,都记在慢查询日志里. redis 的生命周期 客户端向Redis服务器发送命令 ...
- 关于mysql-5.7.13-winx64服务无法启动的解决方法
从官网上下载免安装的5.7的mysql,但是无法启动mysql服务.原因是下载下来的mysql没有data这个文件夹,故需要在cmd下先执行mysql --initialize -insecure命令 ...
- 如何同步多个 git 远程仓库
请看 -> 如何同步多个 git 远程仓库
- 基于C# Socket实现多人网络聊天室
首先不多说,最终实现界面如下,可以通过点击启动服务,开启TCP服务器: 开启TCP服务器之后,可以通过点击客户端,打开一个独立的TCP客户端,打开客户端之后,输入正确的IP地址和端口号,可以进行连接服 ...
- Git复习(六)之标签管理
标签管理 发布一个版本时,我们通常先在版本库中打一个标签(tag),这样,就唯一确定了打标签时刻的版本.将来无论什么时候,取某个标签的版本,就是把那个打标签的时刻的历史版本取出来.所以,标签也是版本库 ...
- git简易操作手册
从远程仓库新建 $ git clone https://github.com/xxxr/Repository.git $ cd Repository/ $ git config --global us ...