题目信息:求分解整数n的个数q(n);能够母函数或者DP

http://acm.hdu.edu.cn/showproblem.php?pid=1028

AC代码:

/******************************

题目大意:求分解整数n的个数q(n)

例:

5 = 5;

5 = 4 + 1;

5 = 3 + 1 + 1;

5 = 3 + 2;

5 = 2 + 2 + 1;

5 = 2 + 1 + 1 + 1;

5 = 1 + 1 + 1 + 1 + 1;

sum(5) = 7;不区分顺序,

(3+2)与(2+3)为同一个

*******************************/

/**

 *DP

 */

#include<iostream>

using namespace std;

int a[121][121];//储存数组

long long q(int n,int m)

{//递归分析,m为分解的最大值

    if((n<1)||(m<1)) return 0;

    if((n==1)||(m==1)) return 1;

    if(n<m) return q(n,n);

    if(n==m) return q(n,m-1)+1;

    return q(n,m-1)+q(n-m,m);

}

/**

int main()

{

    for(int i=1;i<=120;i++){

        for(int j=1;j<=120;j++){//由递归式转存到数组中。降低计算量

            if((i==1)||(j==1)) a[i][j]=1;

            else if(i<j) a[i][j]=a[i][i];

            else if(i==j) a[i][j]=a[i][j-1]+1;

            else a[i][j]=a[i][j-1]+a[i-j][j];

        }

    }

    int n;

    while(cin>>n){

        cout<<a[n][n]<<endl;

    }

    return 0;

}**/

/**

 *母函数解法

 */

int main()

{

    int a[350],b[350],i,j,k,n;

    while(cin>>n&&n)

    {

        for(i=0;i<=n;i++){

            a[i]=1;

            b[i]=0;

        }

        for(i=2;i<=n;i++){

            for(j=0;j<=n;j++)

                for(k=0;k+j<=n;k+=i)

                    b[k+j]+=a[j];

            for(j=0;j<=n;j++){

                a[j]=b[j];

                b[j]=0;

            }

        }

        cout<<a[n]<<endl;

    }

    return 0;

}

hdu1028(母函数+DP)的更多相关文章

  1. hdu刷题2

    hdu1021 给n,看费波纳列数能否被3整除 算是找规律吧,以后碰到这种题就打打表找找规律吧 #include <stdio.h> int main(void) { int n; whi ...

  2. HDU 1398 Square Coins(母函数或dp)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  3. HDU 1028 Ignatius and the Princess III:dp or 母函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 题意: 给你一个正整数n,将n拆分成若干个正整数之和,问你有多少种方案. 注:"4 = ...

  4. hdu 1284 钱币兑换问题 (递推 || DP || 母函数)

    钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  5. E比昨天更多的棒棒糖(Easy+Hrad)(华师网络赛)(DP||母函数||背包优化)

    Time limit per test: 2.0 seconds Memory limit: 512 megabytes 唐纳德先生的某女性朋友最近与唐纳德先生同居.该女性朋友携带一 baby.该 b ...

  6. HihoCoder1339 Dice Possibility(概率DP+母函数)

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 What is possibility of rolling N dice and the sum of the numb ...

  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 1398 Square Coins(母函数或dp)

    Problem Description People in Silverland use square coins. Not only they have square shapes but also ...

  9. 题解报告: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 ...

随机推荐

  1. java面试题之HashMap和TreeMap的区别

    HashMap和TreeMap的区别 相同点: 都是以key和value的形式存储: key不可以重复: 都是线程不安全的: 不同点: HashMap的key可以为空 TreeMap的key值是有序的 ...

  2. linux centos7无法连接ssh

    在centos7连接ssh时,参考了以下博文,终于完美解决 https://blog.csdn.net/trackle400/article/details/52755571 1.  首先,要确保Ce ...

  3. hdu 4353 统计点在三角形内的个数

    Finding Mine Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  4. 驱动12.移植dm9000驱动程序

    1 确定相异性 1.1 选中网卡芯片nGCS4 1.2 确定相异性:基地址,中断号,设置时序(内存控制器BWSCON,BANKCONn) 1.3 修改相应的部分 2 测试DM9000C驱动程序:2.1 ...

  5. Git开发必知必会

    比如说你现在准备写一个自己的视频资源网站,在创业初期,你的项目暂时还是测试阶段,没有用户的时候,你可能只有一个人在开发,你每天都以写的内容和时间作为文件名的命名,这样其实是可以满足你对版本控制的基本需 ...

  6. HDU 5988最小网络流(浮点数)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5988 哇,以前的模版一直T,加了优先队列优化才擦边过. 建图很好建,概率乘法化成概率加法不 ...

  7. Presto查询引擎简单分析

    Hive查询流程分析 各个组件的作用 UI(user interface)(用户接口):提交数据操作的窗口Driver(引擎):负责接收数据操作,实现了会话句柄,并提供基于JDBC / ODBC的ex ...

  8. SnakeYaml使用

    新的项目中需要将yaml文件解析为对象,调研了决定使用snakeYaml,下面看一看怎么使用. 一.引入依赖 因为项目是使用maven构建的,所以我们在pom文件中引入snakeYaml的依赖,如下: ...

  9. POJ1430 Binary Stirling Numbers

    @(POJ)[Stirling數, 排列組合, 數形結合] Description The Stirling number of the second kind S(n, m) stands for ...

  10. VS2010 + WinDDK 搭建驱动开发环境(转)

    因工作需要,需要研究一下Windows驱动开发.我们知道,编译驱动程序主要是通过两种方案:第一种是通过WinDDK提供的build命令+source文件进行编译:另外一种是通过VC的IDE进行编译. ...