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 ...
随机推荐
- sql server第三方产品
sql server第三方产商工具 双活: 1. Moebius for SQL Server :http://www.grqsh.com/Subpage/product_MoebiusDA.html ...
- 【案例分享】SpreadJS金融行业应用实践,开发基于Web Excel的指标补录平台
SpreadJS作为一款基于 HTML5 的纯前端电子表格控件,以“高速低耗.高度类似Excel.可无限扩展”为产品特色,提供移动跨平台和浏览器支持,可同时满足 .NET.Java.App 等应用程序 ...
- Java基础(十)
复习 静态方法与成员方法 //另一个类里的静态和成员方法 public class MyClass { //静态方法 public static void method2() { System.out ...
- 第1章 Java开发入门
一.填空题 1.Java SE.Java EE.Java ME 2.JRE 3.javac 4.bin 5.path.-class path 二.判断题 1.√ 2.× JDK: java devel ...
- MySQL substring_index函数
MySQL substring_index函数 substring_index(str,delim,count) str:要处理的字符串 delim:分隔符 co ...
- MySQL之无限级分类表设计
首先查找一下goods_cates表和table_goods_brands数据表 分别使用命令: root@localhost test>show columns from goods_cate ...
- Ubuntu中配置Python虚拟环境Virtualenv
Ubuntu版本为18.04 Virtualenv介绍 在开发Python应用程序的时候,系统安装的Python3只有一个版本:3.4.所有第三方的包都会被pip安装到Python3的site-pac ...
- idea-代码格式化快捷键设置(2019.1版)
idea默认格式化快捷键是:Ctrl+Alt+L,有时会因其它软件快捷键的冲突导致失灵. 设置方法如下: 1.File --> Settings... 2. Keymap -> Code ...
- Codeforces Round #603 F Economic Difficulties
题目大意 给你两棵树,结点分别是1-A与1-B,然后给了N台设备,并且A树和B树的叶子结点(两棵树的叶子节点数量相同)都是链接电机的.问,最多可以删掉几条边使得每个设备都能连到任意一棵(或两棵)树的根 ...
- 第七篇 CSS盒子
CSS盒子模型 在页面上,我们要控制元素的位置,比如:写作文一样,开头的两个字会空两个格子(这是在学校语文作文一样),其后就不会空出来,还有,一段文字后面跟着一张图,它们距离太近,不好看,我们要移 ...