http://acm.hdu.edu.cn/showproblem.php?pid=1028

dp[i][j]表示数值为i,然后最小拆分的那个数是j的时候的总和。

1 = 1

2 = 1 + 1 、  2 = 2

3 = 1 + 1 + 1、 3 = 2 + 1、 3 = 3

那么可以分两类,

1、最小拆分数是j,这个时候dp[i][j] = dp[i - j][j]。加一个数j,使得它变成i

2、最小拆分数严格大于j,这个时候就没得加上j了。就是dp[i][j + 1]

所以dp[i][j] = dp[i - j][j] + dp[i][j + 1];  (加上dp[i][j + 1]是前缀和的意思)

dp[2][1]就是2中的两条等式,然后dp[3][1] = dp[2][1] + dp[3][2]

其中dp[2][1]中有两条式子,所以每个式子加上一个1上去,就是3中前两条式子。

然后dp[3][2]其实就是3 = 3这条,因为3的式子不存在最小拆分数是2的情况。

如果要输出最小拆分数是k的时候有多少种解。

就是dp[val][k] - dp[val][k + 1];

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int maxn = + ;
int dp[maxn][maxn];
const int N = ;
void init() {
for (int i = ; i <= N; ++i) {
dp[i][i] = ;
for (int j = i - ; j >= ; --j) {
dp[i][j] = dp[i - j][j] + dp[i][j + ];
}
}
// cout << dp[4][1] - dp[4][2] << endl;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
init();
int n;
while (cin >> n) {
cout << dp[n][] << endl;
}
return ;
}

这题居然可以相当于完全背包,整数划分的题目(可以相同)可以转化为完全背包。

dp[i]表示产生这个数字所拥有的合法方案数。

而加了一维,dp[i][j]这样的话,可以用来判断一些特殊条件,例如相差的值不能大于多少这样子。

http://www.cnblogs.com/liuweimingcprogram/p/7010170.html

http://acm.hdu.edu.cn/showproblem.php?pid=2709   (正常dpMLE)

隐含着dp[i][j]

表示前i个物品,组成j的方案数。只能是前i个物品

HDU 1028 Ignatius and the Princess III dp整数划分的更多相关文章

  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 ...

  2. 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 ...

  3. hdu 1028 Ignatius and the Princess III 简单dp

    题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...

  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 ...

  5. 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 ...

  6. HDU 1028 Ignatius and the Princess III (递归,dp)

    以下引用部分全都来自:http://blog.csdn.net/ice_crazy/article/details/7478802  Ice—Crazy的专栏 分析: HDU 1028 摘: 本题的意 ...

  7. hdu 1028 Ignatius and the Princess III 母函数

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  8. 题解报告: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 ...

  9. 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. html5--3.20 新增的keygen元素

    html5--3.20 新增的keygen元素 学习要点 掌握fieldset/legend元素的用法(和figure和figcaption很像,只不过是作用于表单) 了解keygen元素的用法 fi ...

  2. js中的命名空间

    尽量不要使用全局变量,防止环境污染和命名冲突. 所以,将全局变量放在一个命名空间下,是一个好的解决方案. 静态命名空间 1. 直接赋值 这是最基本的方法,但是它很啰嗦,你得重复书写多次变量名.好处是它 ...

  3. 关于 josnp ,解决跨域问题

    JSONP是服务器与客户端跨源通信的常用方法.最大特点就是简单适用,老式浏览器全部支持,服务器不用做任何改造[使用jsonp的时候jsonp: "callback",callbac ...

  4. Swift引用计数器

    ARC概述 和4.2+版本的Xcode对OC的支持一样,Swift也是使用ARC来管理内存,文档是这么描述的: Swift uses Automatic Reference Counting(ARC) ...

  5. Jmeter 施压 SQL server数据库的时候,如何设置?

    1. 在应用Jmeter进行施压之前,有个重要的端口需要手动查找出来.该端口在第三部要使用.开始——程序——microsoft SQL Server 2008R2——配置工具——SQL Server ...

  6. C/C++获取操作系统、CPU、内存信息(windows和linux)

    有时候需要在工程里面获取一些系统或者硬件的信息,比如系统版本,cpu,内存,显卡,硬盘等,作为后续软件功能判断的依据,甚至参与性能算法自适应建模 Windows 操作系统和内存信息在windows下通 ...

  7. springboot中使用@Value读取配置文件

    一.配置文件配置 直接配置 在src/main/resources下添加配置文件application.properties 例如修改端口号 #端口号 server.port=8089 分环境配置 在 ...

  8. samba 安装运行

    samba 安装步骤 1.若之前有安装过相关软件包,先卸载之:sudo apt-get autoremove samba samba-commonsudo apt-get autoremove sys ...

  9. SecureCRT rz上传文件失败

    SecureCRT 将 Windows 上的文件传至 Linux 端,小的文件没有问题能够正常上传,但是对于几百M的文件往往上传过程中失败. 解决办法:使用 rz -be,并且去掉对话框中" ...

  10. 微信小程序开发之三元运算符代替wx.if/wx.else

    直接上代码 实现功能为:当fbphotoFirst为空时,src路径为“pic/信息反馈1-1_14.png“,并且点击事件uploadfbphotoFirst有效,否则为路径fbphotoFirst ...