母函数模板

  1. #include <stdio.h>
  2. #define MAX 10000
  3. int c1[MAX], c2[MAX];
  4. // c1是保存各项质量砝码可以组合的数目
  5. // c2是中间量,保存每一次的情况
  6. // 每个n的种类无限
  7. // (1 + x^1 + x^2 + ...+ x^n)(1 + x^2 + x^4 +....+x^n)(1 + x^3 +...+ x^n)....(1 + x^n)
  8. int main()
  9. {
  10. int n;
  11. while( scanf("%d", &n)!=EOF)
  12. {
  13. for(int i=0; i<=n; i++) //第一项全部至0
  14. {
  15. c1[i]=1; c2[i]=0;
  16. }
  17. for(int i=2; i<=n; i++)
  18. {
  19. for(int j=0; j<=n; j++)
  20. for(int k=0; k+j<=n; k+=i)
  21. c2[k+j] += c1[j]; //一定得是累加
  22. for(int j=0; j<=n; j++) //结束一轮运算赋值
  23. {
  24. c1[j] = c2[j]; c2[j] = 0;
  25. }
  26. }
  27. printf("%d\n", c1[n]);
  28. }
  29. return 0;
  30. }

来自为知笔记(Wiz)

附件列表

时间: 2024-10-08 23:18:31

母函数模板的相关文章

Square Coins (HDU 1398) ———母函数模板详解

Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7748    Accepted Submission(s): 5238 Problem Description People in Silverland use square coins. Not only they have square shapes but

HDU1398 Square Coins 【母函数模板】

Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7995    Accepted Submission(s): 5416 Problem Description People in Silverland use square coins. Not only they have square shapes but

HDU1028 Ignatius and the Princess III 【母函数模板题】

Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12521    Accepted Submission(s): 8838 Problem Description "Well, it seems the first problem is too easy. I will let

(简单母函数模板)hdu 1028 Ignatius and the Princess III

Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14405    Accepted Submission(s): 10142 Problem Description "Well, it seems the first problem is too easy. I will le

组合数学 - 母函数 --- 模板 + 详解

Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8341    Accepted Submission(s): 5674 Problem Description People in Silverland use square coins. Not only they have square shapes but

组合数学 - 母函数 + 模板总结

// Memory Time // 1347K 0MS // by : Snarl_jsb // 2014-09-19-18.23 #include<algorithm> #include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<vector> #include<queue> #include<stack>

HDU2082母函数模板题

找单词 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5782    Accepted Submission(s): 4062 Problem Description 假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于给定的字母,可以找

HDU 2082 母函数模板题

生成函数,英文是Generating Function.恕本人不才,本文只介绍生成函数的其中一种用法. 生成函数是说,构造这么一个多项式函数g(x),使得x的n次方系数为f(n). 对于母函数,我看到最多的是这样两句话: 1.“把组合问题的加法法则和幂级数的乘幂对应起来.” 2.“把离散数列和幂级数一 一对应起来,把离散数列间的相互结合关系对应成为幂级数间的运算关系,最后由幂级数形式来确定离散数列的构造. “ 其实这两句话我也不算太懂.先放这里,说不定以后可能会慢慢理解吧. 还是先举个大牛博客中

组合数学 - 母函数 + 模板题 : 整数拆分问题

Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13129    Accepted Submission(s): 9285 Problem Description "Well, it seems the first problem is too easy. I will let