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

  1. 4
  2. 10
  3. 20

Sample Output

  1. 5
  2. 42
  3. 627
  4.  
  5. 解析:
    母函数入门题,首先母函数
  1. G(x) = (1 + x^1 + x^2..+x^n)(1 + x^2 + x^4 + x^6 + ...)(1 + x^3 + x^6 +..)(..)(1 + x^n)
  2.  
  3. 其中(1 + x^1 + x^2..+x^n)中x的指数为1出现的次数 x^3 ==》 x^(1*3)
    其余同理,比如第二个表达式 (1 + x^2 + x^4 + x^6 + ...) x^2 ==> x^(2*1) x^6 ==> x^(2*3)
  1. 乘法原理的应用:每一个表达式 表示的都是 某个变量的所有取值
    【比如第一个表达式 表示'1'可以取的值(即n拆分后'1'出现的次数)可以为 {012...n}】
  2. 每个变量的所有取值的乘积 就是问题的所有的解(在本问题中表现为‘和’)
  3. 例子:4 = 2 + 1 + 1就是 x^(1 * 2)【'1'出现2次】
  4. * x^(2 * 1)【'2'出现1次】
  5. * x^(3 * 0)【'3'出现0次】
  6. * x^(4 * 0)【..】
  7. 的结果
  1. 所以 G(x)展开后 其中x^n的系数就是 n的拆分解个数
  1.  
  1. # include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int C1[], C2[], n;
  6.  
  7. while(scanf("%d", &n) != EOF)
  8. {
  9. for(int i = ; i <= n; i++)//初始化 第一个表达式 目前所有指数项的系数都为1
  10. {
  11. C1[i] = ;
  12. C2[i] = ;
  13. }
  14.  
  15. for(int i = ; i <= n; i++)//第2至第n个表达式
  16. {
  17. for(int j = ; j <= n; j++)//C1为前i-1个表达式累乘后各个指数项的系数
  18. {
  19. for(int k = ; j + k <= n; k += i)//k为第i个表达式每个项的指数 第一项为1【即x^(i * 0)】(指数k=0),第二项为x^(i * 1)(指数为k=i), 第三项为x^(i * 2)... 所以k的步长为i
  20. {
  21. C2[j + k] += C1[j];//(ax^j)*(x^k) = ax^(j+k) -> C2[j+k] += a 【第i个表达式每一项的系数都为1; a为C1[j]的值(x^j的系数); C2为乘上第i个表达式后各指数项的系数】
  22. }
  23. }
  24. for(int j = ; j <= n; j++)//刷新当前累乘结果各指数项的系数
  25. {
  26. C1[j] = C2[j];
  27. C2[j] = ;
  28. }
  29. }
  30. printf("%d\n",C1[n]);
  31. }
  32.  
  33. return ;
  34. }
  1.  
  1. 出处http://acm.hdu.edu.cn/discuss/problem/post/reply.php?postid=21943&messageid=2&deep=1

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

随机推荐

  1. 在mac安装numpy matplotlib scipy

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #fffff ...

  2. SQLSERVER 的联接查询写法

    1.内连接 语法:[JOIN.INNER JOIN] 作用:两个表相连,加上ON匹配两个表的共同条件. 实例1: SELECT tb_o_i.* FROM tb_o_i INNER JOIN tb_o ...

  3. EFI、GPT和BIOS、MBR

    用了数十年的PC机主板架构是BIOS模式.但在2004年,微软和英特尔共同推出一种名为可扩展固件接口(EFI)的主板升级换代方案.EFI,即可扩展固件接口(Extensible Firmware In ...

  4. mysql中文显示问号

    mysql插入中文后显示为?,查到http://blog.csdn.net/chenxingzhen001/article/details/7567812中方法,即 在my.ini配置文件中的[myd ...

  5. JQ基础语法

    empty HTML 代码: <p>Hello, <span>Person</span> <a href="#">and perso ...

  6. python如何保证多个线程同时修改共享对象时不出错!

    import threadingimport timenumber = 0lock = threading.RLock() #是Lock()的升级版,用Rlock()即可def run(num): l ...

  7. centos6.5安装python3

    1.安装环境 #yum install gcc yum install zlib-devel yum install make 2.下载python版本 #wget http://www.python ...

  8. selenium自动化遇见Cannot find class in classpath问题

    今天遇见了Cannot find class in classpath的问题, org.testng.TestNGException: Cannot find class in classpath: ...

  9. cuckoo数据库变更

    1.cuckoo版本升级 cuckoo默认的数据库为sqlite,默认连接方式为sqlite:///os.path.join(REPORT_ROOT, "db", "cu ...

  10. 最直接的教你OC中Block的简单使用场景

    场景一: A控制器跳转到B控制器   --   B控制器事件处理通过Block回调给A控制器 A 跳转前界面如下 点击ToB按钮到控制器B 在控制器B中点击按钮返回到A界面如下             ...