---恢复内容开始---

2017-08-10 20:00:45

writer:pprp

拆分数:

  把正整数n拆分成k个正整数之和的方案数;

问题转换:将1转化为2

  1、把n表示成m个正整数之和的方案数

  2、把n表示成不超过m的正整数之和的方案数

两者答案相同:解释Ferrers图

用dp来做,dp[i][j]的意思是 i 表示成 不超过 j 的方案数

边界条件:

  dp[0][j] = 1 , dp[[i][1] = 1 , dp[1][j] = 1;

状态转移:

  dp[i][j] = dp[i][j-1]+dp[i-j][j];  

  n个数划分成不超过m的整数的方案,若最大数为m,那么把最大数去掉,等价于把n-m分成不超过m的整数的方案,

  若最大数不是m,那么等价于把n分成不超过m-1的方案数


代码如下:

#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio> using namespace std; const int maxn = ;
int dp[maxn][maxn]; void DP()
{
for(int i = ; i < maxn ; i++)
{
dp[i][] = dp[][i] = dp[][i] = ;
}
for(int i = ; i < maxn ; i++)
{
for(int j = ; j < maxn ; j++)
{
if(i >= j)
dp[i][j] = dp[i][j-]+dp[i-j][j];
else
dp[i][j] = dp[i][i];
}
}
} int main()
{
int n;
memset(dp,,sizeof(dp)); DP(); while(cin >> n)
{
cout << dp[n][n] << endl;
}
return ;
}

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 (递归,dp)

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

  3. hdu acm 1028 数字拆分Ignatius and the Princess III

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

  4. Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数

    Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...

  5. HDU 1028 整数拆分问题 Ignatius and the Princess III

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

  6. Ignatius and the Princess III

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

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

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

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

  9. HDU1028 Ignatius and the Princess III 【母函数模板题】

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

随机推荐

  1. Redis集群部署文档(Ubuntu15.10系统)

    Redis集群部署文档(Ubuntu15.10系统)(要让集群正常工作至少需要3个主节点,在这里我们要创建6个redis节点,其中三个为主节点,三个为从节点,对应的redis节点的ip和端口对应关系如 ...

  2. Appium+python移动端自动化测试-python库及pycharm安装(二)

    一.安装python库 安装python库有很多种方法,如pip安装.源文件安装.运行包安装,但我们最常用的就是使用pip进行安装 Appium+python做移动端的自动化测试,所需要安装以下pyt ...

  3. Python性能优化的20条建议

    优化算法时间复杂度 算法的时间复杂度对程序的执行效率影响最大,在Python中可以通过选择合适的数据结构来优化时间复杂度,如list和set查找某一个元素的时间复杂度分别是O(n)和O(1).不同的场 ...

  4. PHP归档phar性能測试

    PHP自从5.3后新增PHAR归档,Phar 归档的概念来自 Java™ 技术的 JAR 归档,它同意使用单个文件打包应用程序.这个文件里包括运行应用程序所需的全部东西.该文件不同于单个可运行文件,后 ...

  5. layer插件的常用实例

    layer.msg(提示信息, {time:1000, icon:5, shift:6}, 回调方法); layer.alert(提示信息, function(index){ // 回调方法 laye ...

  6. R语言之多重共线性的判别以及解决方法

    多重共线性(Multicollinearity)是指线性回归模型中的解释变量之间由于存在精确相关关系或高度相关关系而使模型估计失真或难以估计准确.   1.可以计算X矩阵的秩qr(X)$rank,如果 ...

  7. 20165324 学习基础与C语言学习心得

    20165324 技能学习心得与C语言学习 一.读后感及技能学习 做中学读后感 我认为给学生具体的, 能实践的, 能马上看到因果关系的教材和练习, 是激发学生兴趣, 好奇心, 求知欲的好方法. 我就是 ...

  8. boost单元测试框架

    头文件: #include <boost/test/unit_test.hpp> 编译加:-lboost_unit_test_framework 单元测试: 需要定义BOOST_TEST_ ...

  9. CCF 权限查询(模拟)

    试题编号: 201612-3 试题名称: 权限查询 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 授权 (authorization) 是各类业务系统不可缺少的组成部分,系统 ...

  10. 基于EasyUI 快速搭建权限管理平台

    前言: 一.用户角色权限设计思路: <1>不同职责的人员,对于系统操作的权限应该是不同;<2>可以对“组”进行权限分配;<3>权限管理系统应该是可扩展的;<4 ...