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

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. Mysql日常操作

    创建用户并授权 grant all privileges on test.* to "test"@"localhost" identified by " ...

  2. python [:-1] 与 [::-1]

    line = "abcde"line[:-1]结果为:'abcd' line = "abcde"line[::-1]结果为:'edcba' [:-1] b = ...

  3. python学习笔记(十五)异常处理

    python解析器去执行程序,检测到了一个错误时,触发异常,异常触发后且没被处理的情况下,程序就在当前异常处终止,后面的代码不会运行,所以你必须提供一种异常处理机制来增强你程序的健壮性与容错性 . 例 ...

  4. PAT 1049 Counting Ones [难]

    1049 Counting Ones (30 分) The task is simple: given any positive integer N, you are supposed to coun ...

  5. lower_bound()函数,upper_bound()函数

    1.查找:STL中关于二分查找的函数有三个lower_bound .upper_bound .binary_search .这三个函数都运用于有序区间(当然这也是运用二分查找的前提),下面记录一下这两 ...

  6. 1-CommonJs

    诞生背景JS没有模块系统.标准库较少.缺乏包管理工具:前端端没有模块化编程还可以,因为前端逻辑没那么复杂,可以工作下去,在服务器端逻辑性那么强必须要有模块为了让JS可以在任何地方运行,以达到Java. ...

  7. Spring自动装配Bean的五种方式

    在Spring中,支持 5 自动装配模式. no – 缺省情况下,自动配置是通过“ref”属性手动设定,在项目中最常用byName – 根据属性名称自动装配.如果一个bean的名称和其他bean属性的 ...

  8. 腾讯 微信春招nlp实习生一面二面(猝)

    一面: 1.算法题: 1 28数组中出现次数超过一半的数字 2 手写快排:八大排序算法总结(2) 2.项目介绍: 大多都是项目中涉及到的技术. TFIDF 的原理 word2vec的原理 3.算法原理 ...

  9. Lua 基础总结

    lua 数组下标从 1 开始, 不是 0 lua 逻辑运算符  与 或 非  就是英文  and  or  not local  局部变量 数据类型:lua是一门动态类型语言,变量没有类型,只有值才有 ...

  10. 无密码ssh操作步骤备忘

    需求:A机器无密码登陆到B机器 1.A机器执行   ssh-keygen -t rsa  ,在~/.ssh/下生成id_rsa 和  id_rsa.pub两个文件,其中id_rsa.pub是公匙 2. ...