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. x264 FFmpeg Options Guide

    https://sites.google.com/site/linuxencoding/x264-ffmpeg-mapping x264 FFmpeg Options Guide Please Not ...

  2. iPhone HTTP获得XML并使用GDataXML解析

    1. [代码][C/C++]代码     NSURL *url = [NSURL URLWithString:  @"http://www.raywenderlich.com/downloa ...

  3. struts2 小例子(教训篇)

    学了一阵子的struts2了,到了最后,想自己写个小程序,发现最简单的配置文件都 竟然能弄错,是我这几天睡眠不足么.怎么可能,爱好这门的,怎么会这样.这样真的很伤心啊.小小心灵受不了这种打击啊.... ...

  4. Android Studio中的“favorites”和“bookmark”

    做项目难免来回查看某个文件的某个方法,某些文件可能访问率很高, 为了加快开发效率楼主推荐使用favorites (文件)bookmark (代码 行). favorites 的添加就在文件单击右键ad ...

  5. 002-Fatal error in launcher: Unable to create process using '""

    这个问题出在先安装Python3之后再安装python2, 使用pip安装的时候出现的故障 原因是python3的环境变量写入在了用户的环境变量上 但是一旦安装python2之后, Python会把信 ...

  6. SPOJ Find the max XOR value(二进制,贪心即可)

    You have two integers L and R, and you are required to find the max xor value of a and b where L < ...

  7. gulp --- 前端自动化构建工具

    目录 1. gulp使用步骤 1.1 安装Node.js 1.2 全局安装gulp 1.3 安装项目依赖包gulp 1.3.1 了解package.json 1.3.2 根据package.json安 ...

  8. C# 获取QQ群数据的实现

    一,分析 1,群数据获取 当访问http://qun.qq.com/air/#mygroup我们通过Fiddler可以查看到QQ群列表是从http://qun.qq.com/air/group/min ...

  9. PHP多种序列化/反序列化的方法 json_encode json_decode

    序列化是将变量转换为可保存或传输的字符串的过程:反序列化就是在适当的时候把这个字符串再转化成原来的变量使用.这两个过程结合起来,可以轻松地存储和传输数据,使程序更具维护性. 1. serialize和 ...

  10. Python批量操作Linux服务器执行命令

    #-*- coding: utf-8 -*- #!/usr/bin/python import paramiko import threading def ssh2(ip,username,passw ...