题目信息:求分解整数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面试题之java中用到的线程调度算法是什么

    抢占式.一个线程用完CPU之后,操作系统会根据线程优先级.线程饥饿情况等数据算出一个总的优先级并分配下一个时间片给某个线程执行. 操作系统中可能会出现某条线程常常获取到VPU控制权的情况,为了让某些优 ...

  2. 线段树懒标记好题 HDU4578

    (1)"1 x y c",代表 把区间 [x,y] 上的值全部加c (2)"2 x y c",代表 把区间 [x,y] 上的值全部乘以c (3)"3 ...

  3. Java-二叉树-插入、删除、遍历

    二叉树的具体特性和细节知识点,自行百度,直接上代码. 节点:节点内容.左子孩子.右子孩子.父亲 class Node { private int data; private Node leftChil ...

  4. QBXT 二月五号整理

    给你一列数, 询问和最大的子串. N<=10^6 // N <=10^6 #include<cstdio> #include<iostream> using nam ...

  5. vue.js源码学习分享(九)

    /* */ var arrayKeys = Object.getOwnPropertyNames(arrayMethods);//获取arrayMethods的属性名称 /** * By defaul ...

  6. hdu 4503(数学,概率)

    湫湫系列故事——植树节 Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total ...

  7. js、jq平时积累

    1.window.onbeforeunload   =   function(){$(window).scrollTop(0);}  //在即将离开当前页面(刷新或关闭)时执行 JavaScript ...

  8. AC日记——小行星 洛谷 P2711

    题目背景 pid=3437 题目描述 星云中有n颗行星,每颗行星的位置是(x,y,z).每次可以消除一个面(即x,y或z坐标相等)的行星,但是由于时间有限,求消除这些行星的最少次数. 输入输出格式 输 ...

  9. iOS应用内跳转百度高德苹果地图

    移动开发经常用到基于位置的一些导航功能,但是对于对导航功能依赖性不强的的应用,我们直接采用应用外跳转地图APP即可. 但是应用间跳转,首先需要设置白名单, 在iOS 9 下涉及到平台客户端跳转,系统会 ...

  10. Object 转 String

    做项目中 : map 为Map<String,Object> a.setmoney(new BigDecimal((String)map.get("money"))); ...