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

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. Windows 下配置 php_imagick 扩展

    1.首先按装 imageimagick 可以去 http://imagemagick.org/script/binary-releases.php#windows 这里下载,看好自己的系统环境和选择好 ...

  2. Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F 表情插入mysql 报错

    导致报错的问题是 emoji表情是4位 mysql 5.5.3版本以下数据库(utf8格式为3位),不支持.需要更新mysql5.5.3及以上的版本数据库并设置默认或者表或者字段的格式为 utf8mb ...

  3. CNI插件编写框架分析

    概述 在<CNI, From A Developer's Perspective>一文中,我们已经对CNI有了较为深入的了解.我们知道,容器网络功能的实现最终是通过CNI插件来完成的.每个 ...

  4. Python下的正则表达式原理和优化笔记

    摘要: 本文旨在总结一些编写表达式的技巧和原理.鉴于介绍python中re模块的使用方法的文章太多.所以本文在基础方面都是略过,而在回溯原理和一些技巧方面记录一点点学习总结. 目录:[ - ] 基础规 ...

  5. HTTP错误404.2-Not Found ,模块CgiModule,错误代码0x800704ec

    目录 问题案例 解决问题 问题案例 错误:HTTP 错误 404.2 - Not Found. 由于 Web 服务器上的“ISAPI 和 CGI 限制”列表设置,无法提供您请求的页面. 解决问题 网上 ...

  6. 入参是小数的String,返回小数乘以100的String

    String money = request.getParameter("orderAmt"); BigDecimal moneyDecimal = new BigDecimal( ...

  7. 文件传输(xmodem协议)

    https://www.menie.org/georges/embedded/ 需要移植如下两个基础的硬件读写函数 int _inbyte(unsigned short timeout); void ...

  8. CentOS6.8 yum 安装 mysql5.7.12 完美步骤

    一,wget http://dev.mysql.com/get/mysql57-community-release-el6-8.noarch.rpm 二,yum localinstall mysql5 ...

  9. 使用python操作文件实现购物车程序

    使用python操作文件实现购物车程序 题目要求如下: 实现思路 始终维护一张字典,该字典里保存有用户账号密码,购物车记录等信息.在程序开始的时候读进来,程序结束的时候写回文件里去.在登录注册的部分, ...

  10. PHPCMS 小节

    当前栏目id:                       {$catid}当前栏目名:                       {$CATEGORYS[$catid][catname]}当前栏目 ...