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 ...
随机推荐
- hive_UDTF函数
hive的UDTF函数是可以输入一行数据然后输出多行多列(可以是单行/单列)的函数 public class Tex extends GenericUDTF { /** * 对传入的参数进行初始化 * ...
- Keras模型训练的断点续训、早停、效果可视化
训练:model.fit()函数 fit(x=None, y=None, batch_size=None, epochs=, verbose=, callbacks=None, validation_ ...
- 用java语言(文件和文件流知识点)实现图片的拷贝,从d盘拷贝到e盘
/** * 实现图片的拷贝\ * 注意:用的是文件字节流 */ package com.test4; import java.io.*; public class Demo12_4 { /** * @ ...
- vue 组件基本使用
组件的基本使用 注册组件 注册组件就是利用Vue.component()方法,先传入一个自定义组件的名字,然后传入这个组件的配置.vue.component()注册的全局组件 Vue.componen ...
- 创建全文索引----SQLserver
1.启动 Microsoft Search 服务 开始菜单-->SQL程序组-->服务管理器-->下拉筐-->Microsoft Search 服务-->启动它. 2. ...
- vs编译项目报错:The OutputPath property is not set for this project
今天使用VS2008编译项目时报错: The OutputPath property is not set for this project. Please check to make sure t ...
- LLVM 词典
#LLVM 词典 ## 本文转自https://github.com/oxnz/clang-user-manual/blob/master/LLVM-Language-Reference-Manual ...
- 享元模式<Flyweight Pattern>
1.What-是什么? 享元模式是一种轻量级的结构型模式.旨在以共享的方式高效的支持大量的细粒度对象的复用.要求能够共享的对象必须是细粒度对象,这些对象比较相似,状态变化小. 2.Why-为什么? ...
- mysql alter 语句用法,添加、修改、删除字段、索引、主键等
修改表名: ALTER TABLE admin_user RENAME TO a_use //增加主键 [sql] view plaincopy alter table tabelname add ...
- linux进程调度的算法
linux进程的调度算法 这节我们来学习一下linux进程的优先级 linux进程的优先级 进程提供了两种优先级,一种是普通的进程优先级,第二个是实时优先级,前者使用SCHEED_NORMAL调度策略 ...