Ignatius and the Princess III

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20918    Accepted Submission(s): 14599

Problem Description
"Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says.

"The second problem is, given an positive integer N, we define an equation like this:
  N=a[1]+a[2]+a[3]+...+a[m];
  a[i]>0,1<=m<=N;
My question is how many different equations you can find for a given N.
For example, assume N is 4, we can find:
  4 = 4;
  4 = 3 + 1;
  4 = 2 + 2;
  4 = 2 + 1 + 1;
  4 = 1 + 1 + 1 + 1;
so the result is 5 when N is 4. Note that "4 = 3 + 1" and "4 = 1 + 3" is the same in this problem. Now, you do it!"
 
Input
The input contains several test cases. Each test case contains a positive integer N(1<=N<=120) which is mentioned above. The input is terminated by the end of file.
 
Output
For each test case, you have to output a line contains an integer P which indicate the different equations you have found.
 
Sample Input
4
10
20
 
Sample Output
5
42
627

母函数:生成函数即母函数,是组合数学中尤其是计数方面的一个重要理论和工具。生成函数有普通型生成函数和指数型生成函数两种,其中普通型用的比较多。形式上说,普通型生成函数用于解决多重集的组合问题,而指数型母函数用于解决多重集的排列问题。母函数还可以解决递归数列的通项问题(例如使用母函数解决斐波那契数列的通项公式)。

(百度百科的东西,大家估计也不想看,请看下面这个公式)

以展开后的x4为例,其系数为4,即4拆分成1、2、3之和的拆分数为4;

即 :4=1+1+1+1=1+1+2=1+3=2+2

再引出两个概念整数拆分和拆分数:

整数拆分即把整数分解成若干整数的和(相当于把n个无区别的球放到n个无标志的盒子,盒子允许空,也允许放多于一个球)。

整数拆分成若干整数的和,办法不一,不同拆分法的总数叫做拆分数

 /*
     Name: hdu--1028--Ignatius and the Princess III
     Copyright: 2017 日天大帝
     Author: 日天大帝
     Date: 22/04/17 16:36
     Description: 母函数,对应上面那个公式,更容易做这道题
 */
 #include<iostream>
 using namespace std;
 ],c2[];
 int main()
 {
     ,i;
     ;i <= n; i++){
         c1[i] = ;//母函数第一个因子,全为1,c1保存前面i-1个因子相乘的结果,首先对c1初始化,由第一个表达式(1+x+x2+..xn)初始化,把质量从0到n的所有砝码都初始化为1.
         c2[i] = ;
     }
     ;i<=n;i++){//操作第i个括号,i从2到n遍历,这里i就是指第i个表达式,上面给出的母函数关系式里,每一个括号括起来的就是一个表达式。
         ; j<= n;j++){//对于指数为j的进行操作,j 从0到n遍历,这里j就是只一个表达式里第j个变量,比如在第二个表达式里:(1+x2+x4....)里,第j个就是x2*j.
              ;k+j<=n;k+=i){//把第i个的每一个数与之前的结果相乘,k表示的是第j个指数,所以k每次增i(因为第i个表达式的增量是i)。
                 c2[j+k]+=c1[j];//j+k指数相加,他的值就是这个指数的系数,
             }
         }
         ;j<=n;j++){//系数保存在前面一个数组中
             c1[j] = c2[j];//把c2的值赋给c1,而把c2初始化为0,因为c2每次是从一个表达式中开始的
             c2[j] = ;
         }
     }
     while(cin>>n)cout<<c1[n]<<endl;
     ;
 }

hdu--1028--Ignatius and the Princess III (母函数)的更多相关文章

  1. hdu 1028 Ignatius and the Princess III 母函数

    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

    题目链接:hdu 1028 Ignatius and the Princess III 题意:对于给定的n,问有多少种组成方式 思路:dp[i][j],i表示要求的数,j表示组成i的最大值,最后答案是 ...

  3. HDU 1028 Ignatius and the Princess III 整数的划分问题(打表或者记忆化搜索)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1028 Ignatius and the Princess III Time Limit: 2000/1 ...

  4. 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 ...

  5. 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 ...

  6. hdu 1028 Ignatius and the Princess III (n的划分)

    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 (生成函数/母函数)

    题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...

  8. HDU 1028 Ignatius and the Princess III (递归,dp)

    以下引用部分全都来自:http://blog.csdn.net/ice_crazy/article/details/7478802  Ice—Crazy的专栏 分析: HDU 1028 摘: 本题的意 ...

  9. HDU 1028 Ignatius and the Princess III (动态规划)

    题目链接:HDU 1028 Problem Description "Well, it seems the first problem is too easy. I will let you ...

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

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

随机推荐

  1. mongodb入门级的视频教程-简易客户管理系统制作

    本套教程作为mongodb入门级的视频教程,首先讲解了mongodb的下载.安装,环境变量的设置.启动mongodb和将mongodb安装成为windows服务.然后进一步讲解了mongodb里面集合 ...

  2. 如何使用Node.js编写命令工具——以vue-cli为例

    vue-cli全局安装之后,提供了vue命令和vue init.vue list.vue build三个子命令,通过命令可以搭建基于vue.js的脚手架项目.本文简单介绍一下这些命令是如何实现的. v ...

  3. java常见字符串的操作

    /** * java常见字符串的操作 */ public class Test7 { public static void main(String args[]){ StringBuffer sBuf ...

  4. PHP安装phpredis扩展

    phpredis 的github地址:https://github.com/nicolasff/phpredis第一步:切换到指定的目录,然后wget https://github.com/nicol ...

  5. 使用Scribefire在博客中插入语法高亮

    效果如下, 文字1 int cool void main() { cout<<"hello world!"<<endl } 文字2 经过一番折腾,终于搞定了 ...

  6. if和for的几个经典题目

    1.有一对幼兔,幼兔1个月后长成小兔,小兔1个月后长成成兔并生下一对幼兔,问几年后有多少对兔子,幼兔.小兔.成兔对数分别是多少. 幼兔 1 小兔 0 成兔 0幼兔 0 小兔 1 成兔 0 幼兔 1 小 ...

  7. Python系列教程(三):输入和输出

    1.1 raw_input() 在Python中,获取键盘输入的数据的方法是采用 raw_input 函数(至于什么是函数,咱们以后的章节中讲解),那么这个 raw_input 怎么用呢? 看如下示例 ...

  8. 微信开发之获取jsapi_ticket

    一.获取流程 1.获取 access_token 2.通过access_token换取 jsapi_ticket 3.签名算法 签名生成规则如下:参与签名的字段包括noncestr(随机字符串), 有 ...

  9. springmvc4.0配置ajax请求json格式数据

    1.导入相关jar包:jackson-annotation-2.5.4.jar,jackson-core-2.5.4.jar,jackson-databind-2.5.4.jar. 2.spring- ...

  10. ssh自动化出现的莫名报错

    代码如: ssh -q user@host <<EOF localhost EOF 会出现提示如: Pseudo-terminal will not be allocated becaus ...