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

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. 《Monitoring and Tuning the Linux Networking Stack: Receiving Data》翻译

    Overview 从宏观的角度来看,一个packet从网卡到socket接收缓冲区的路径如下所示: 驱动加载并初始化 packet到达网卡 packet通过DMA被拷贝到内核中的一个ring buff ...

  2. MySQL与Btree

    Btree,B+tree,B*tree 前言: 由于在查找中用二分法在查找一些边缘数据时就会产生数据查找不公平,二叉树也存在类似问题:所以就有了B-tree. B+树索引是B+树在数据库中的一种实现, ...

  3. jquery prop attr

    checked比较特殊,只要设置了属性checked,不管何值都是checked的.例如:<input type="checkbox" checked><inpu ...

  4. error: https://packages.elastic.co/GPG-KEY-elasticsearch: import read failed(2).

    安装filebeat报错: curl: (35) SSL connect errorerror: https://packages.elastic.co/GPG-KEY-elasticsearch: ...

  5. Flask系列(十)自定义Form组件

    一.wtforms源码流程 1.实例化流程分析 # 源码流程 1. 执行type的 __call__ 方法,读取字段到静态字段 cls._unbound_fields 中: meta类读取到cls._ ...

  6. JVM内存四大类型:Heap,Stack,Contant,DirectMemory等

    Stack属于栈的区域,属于每条线程私有的. 方法区和本地方法栈有很大的不同,方法区是用Java级别角度做的代码,本地方法栈指向的是C/C++. Java开发,对象就在堆中,一般而言,堆中只有对象. ...

  7. Tomcat启动慢但是不报错的解决办法

    参考文章:https://blog.csdn.net/xiaoxinyu316/article/details/39064003 可以查看下tomat的启动日志,看看有哪些比较耗时的操作: grep ...

  8. 《FTL之垃圾回收、写放大和OP 》总结

    来自 http://www.ssdfans.com/?p=1840: 写放大WA: 对空盘来说(未触发GC),写放大一般为1,即Host写入多少数据,SSD写入闪存也是多少数据量(这里忽略SSD内部数 ...

  9. 【MYSQL】主从常见问题运维

    参见Mysql主从常见错误,http://hzcsky.blog.51cto.com/1560073/479476

  10. C++学习笔记--异常简介

    C++异常是对程序运行过程中发生的异常情况(如被0除)的一种响应.异常提供了将控制权从程序的一个部分传递到另一部分的途径. 1.对异常的处理有3个部分组成: (1)引发异常 (2)捕获有处理程序的异常 ...