生成函数(母函数)

母函数又称生成函数。定义是给出序列:a0,a1,a2,...ak,...an,

那么函数G(x)=a0+a1*x+a2*x2+....+ak*x+...+an* xn  称为序列a0,a1,a2,.......ak,......的母函数(即生成函数)。

1. 问题 n=x1+x2+x3+...+xk有多少个非负整数解?这道题是学排列与组合的经典例题了。

把每组解的每个数都加1,就变成n+k=x1+x2+x3+...+xk的正整数解的个数了。

教材上或许会出现这么一个难听的名字叫“隔板法”:把n+k个东西排成一排,在n+k-1个空格中插入k-1个“隔板”。

答案我们总是知道的,就是C(n+k-1,k-1)。它就等于C(n+k-1,n)。

它关于n的生成函数是g(x)=1/(1-x)^k。

2. 这个公式非常有用,是把一个生成函数还原为数列的武器。而且还是核武器。1/(1-x)^n=1+C(n,1)x^1+C(n+1,2)x^2+C(n+2,3)x^3+...+C(n+k-1,k)x^k+...。

详情参考 百度百科  博客

找单词

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9784    Accepted Submission(s): 6805

Problem Description
假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26。那么,对于给定的字母,可以找到多少价值<=50的单词呢?单词的价值就是组成一个单词的所有字母的价值之和,比如,单词ACM的价值是1+3+14=18,单词HDU的价值是8+4+21=33。(组成的单词与排列顺序无关,比如ACM与CMA认为是同一个单词)。
 
Input
输入首先是一个整数N,代表测试实例的个数。
然后包括N行数据,每行包括26个<=20的整数x1,x2,.....x26.
 
Output
对于每个测试实例,请输出能找到的总价值<=50的单词数,每个实例的输出占一行。
 
Sample Input
2
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
9 2 6 2 10 2 2 5 6 1 0 2 7 0 2 2 7 5 10 6 10 2 10 6 1 9
 
Sample Output
7
379297
 
解析  相当于G(x)=(1++) (1+++…)…(1++…)  每一个多项式 i 有xi+1项  然后多项式乘法就好了
  1. #include <bits/stdc++.h>
  2. #define mp make_pair
  3. #define pb push_back
  4. #define fi first
  5. #define se second
  6. #define all(a) (a).begin(), (a).end()
  7. #define fillchar(a, x) memset(a, x, sizeof(a))
  8. #define huan printf("\n");
  9. #define debug(a,b) cout<<a<<" "<<b<<" "<<endl;
  10. using namespace std;
  11. const int maxn= 1e2+;
  12. const int inf = 0x3f3f3f3f;
  13. typedef long long ll;
  14. ll a[maxn],b[maxn];
  15. int main()
  16. {
  17. int t;
  18. cin>>t;
  19. while(t--)
  20. {
  21. fillchar(a,);
  22. fillchar(b,);
  23. a[]=;
  24. for(int i=;i<=;i++)
  25. {
  26. int x;
  27. cin>>x;
  28. for(int j=;j<=;j++)
  29. {
  30. for(int k=;k<=x&&(j+i*k<=);k++)
  31. {
  32. b[j+k*i]+=a[j];
  33. }
  34.  
  35. }
  36. for(int j=;j<=;j++)
  37. {
  38. a[j]=b[j];
  39. b[j]=;
  40. }
  41. }
  42. ll ans=;
  43. for(int i=;i<=;i++)
  44. {
  45. ans+=a[i];
  46. }
  47. cout<<ans<<endl;
  48. }
  49. }

Ignatius and the Princess III

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

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
 
解析  这道题用母函数更裸一点 直接多项式乘法就好了  不过有一个递推的解法  记忆化一下就可以 减少很大计算量 或者dp
整数划分  还有一些其他的定理

递推法

根据n和m的关系,考虑下面几种情况:
(1)当n=1时,不论m的值为多少(m>0),只有一种划分,即{1};
(2)当m=1时,不论 的值为多少(n>0),只有一种划分,即{1,1,....1,1,1};
(3)当n=m时,根据划分中是否包含n,可以分为两种情况:
(a)划分中包含n的情况,只有一个,即{n};
(b)划分中不包含n的情况,这时划分中最大的数字也一定比n小,即n的所有(n-1)划分;因此,f(n,n) = 1 + f(n, n - 1)。
(4)当n<=m时,由于划分中不可能出现负数,因此就相当于f(n,n);
(5)当n>m时,根据划分中是否包含m,可以分为两种情况:
(a)划分中包含 的情况,即{m,{x1,x2,x3,...,xi}},其中{x1,x2,x3,...,xi}的和为n-m,可能再次出现m,因此是(n-m)的m划分,因此这种划分个数为f(n-m,m;
(b)划分中不包含m的情况,则划分中所有值都比m小,即n的(m-1)划分,个数为f(n,m-1;因此,f(n,m)=f(n-m,m)+f(n,m-1) 。
  1. #include <bits/stdc++.h>
  2. #define mp make_pair
  3. #define pb push_back
  4. #define fi first
  5. #define se second
  6. #define all(a) (a).begin(), (a).end()
  7. #define fillchar(a, x) memset(a, x, sizeof(a))
  8. #define huan printf("\n");
  9. #define debug(a,b) cout<<a<<" "<<b<<" "<<endl;
  10. using namespace std;
  11. const int maxn= 1e2+;
  12. const int inf = 0x3f3f3f3f;
  13. typedef long long ll;
  14. ll a[maxn],b[maxn];
  15. int main()
  16. {
  17. int n;
  18. while(cin>>n)
  19. {
  20. fillchar(a,);
  21. fillchar(b,);
  22. a[]=;
  23. for(int i=;i<=n;i++) //枚举第i个多项式 每一项的系数都为1
  24. {
  25. for(int j=;j<=n;j++) //保留x0----xn项
  26. {
  27. for(int k=;j+i*k<=n;k++) //枚举第i个多项式的每一项
  28. {
  29. b[j+k*i]+=a[j]; //b数组保存中间值
  30. }
  31.  
  32. }
  33. for(int j=;j<=n;j++)
  34. {
  35. a[j]=b[j]; //b数组传值给a
  36. b[j]=;
  37. }
  38. }
  39. cout<<a[n]<<endl;
  40. }
  41. }
  42. /*----------------------------------------------------------------------------------------*/
  43. #include<bits/stdc++.h>
  44. #define ll long long
  45. using namespace std;
  46. //记忆化递归法求解整数划分
  47. ll ans[][];
  48. ll GetPartitionCount(int n, int m)
  49. {
  50. if(ans[n][m]>)
  51. return ans[n][m];
  52. if (n == || m == )return ans[n][m]=;
  53. if (n < m)return ans[n][m]=(GetPartitionCount(n, n));
  54. if (n == m)return ans[n][m]=( + GetPartitionCount(n, n - ));
  55. else return ans[n][m]=(GetPartitionCount(n - m, m) + GetPartitionCount(n, m - ));
  56. }
  57.  
  58. int main()
  59. {
  60. int n,m;
  61. ll sum;
  62. while (scanf("%d",&n)==)
  63. {
  64. memset(ans,,sizeof(ans));
  65. m=n;
  66. sum = GetPartitionCount(n, m);
  67. printf("%lld\n", sum);
  68. }
  69. return ;
  70. }

HDU 1028 整数拆分 HDU 2082 找单词 母函数的更多相关文章

  1. Ignatius and the Princess III HDU - 1028 || 整数拆分,母函数

    Ignatius and the Princess III HDU - 1028 整数划分问题 假的dp(复杂度不对) #include<cstdio> #include<cstri ...

  2. HDOJ 2082 找单词 (母函数)

    找单词 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  3. hdu,1028,整数拆分的理解

    #include"iostream"using namespace std;int main() { int n,i,j,k; int c[122],temp[122]; //c[ ...

  4. HDU 1028 整数拆分问题 Ignatius and the Princess III

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  5. HDU 2082 找单词 (普通型 数量有限 母函数)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2082 找单词 Time Limit: 1000/1000 MS (Java/Others)    Me ...

  6. hdu acm 2082 找单词

    找单词 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  7. HDU 1028 Ignatius and the Princess III(母函数整数拆分)

    链接:传送门 题意:一个数n有多少种拆分方法 思路:典型母函数在整数拆分上的应用 /********************************************************** ...

  8. HDU 1028 Ignatius and the Princess III (生成函数/母函数)

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

  9. hdu2082 找单词 (母函数)

    找单词 题意: 中文题,考虑是不是要写个英文题意..(可惜英语水平不够  囧rz)                (题于文末) 知识点: 母函数(生成函数): 生成函数有普通型生成函数和指数型生成函数 ...

随机推荐

  1. es5/6数组遍历以及常用的一些方法

    数组的遍历方法 1...for(var i=0;i<arr.length;i++){ } ---------------------------------------------------- ...

  2. InvocationTargetException异常的深入研究-servlet的setAttribute与getAttribute

    在某项目中,前端jsp传入的用户id数据通过session域传入后台servlet进行处理的过程中,无意间出现了InvocationTargetException异常 前端部分代码如下:测试代码,非原 ...

  3. Android(java)学习笔记173:服务(service)之绑定服务的细节

    绑定服务的细节 1. 如果onbind方法返回值是null,onServiceConnect方法就不会被调用: 2. 绑定的服务,在系统设置界面,正在运行条目是看不到的: 3. 绑定的服务,不求同时生 ...

  4. 安装 配置 IIS

    一  .找到    控制面板 ------  在程序和功能  -----打开或关闭window 功能 :这里可能要等一下 才会显示 . 二‘.找到  Internet信息服务 ,勾选大部分如下图:点击 ...

  5. SoapUI对于Json数据进行属性值获取与传递

    SoapUI的Property Transfer功能可以很好地对接口请求返回的数据进行参数属性获取与传递,但对于Json数据,SoapUI会把数据格式先转换成XML格式,但实际情况却是,转换后的XML ...

  6. 《3+1团队》【Alpha】Scrum meeting 3

    项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 3+1团队 团队博客地址 https://home.cnblogs.com/u/3-1group ...

  7. mybaits2-Dao开发

    项目结构: 1.创建project,导入相关依赖(前提).配置db.properties与mybaits-config #mysql驱动 db.driver=com.mysql.jdbc.Driver ...

  8. No-2.常用 Linux 命令的基本使用

    常用 Linux 命令的基本使用 01. 学习 Linux 终端命令的原因 Linux 刚面世时并没有图形界面,所有的操作全靠命令完成,如 磁盘操作.文件存取.目录操作.进程管理.文件权限 设定等 在 ...

  9. xcode中自定义log打印

    打印内容包括 在哪个文件中 ? 在哪个方法中? 将要执行什么操作?   // 此打印实现前提: // 1.在.pch文件中实现自定义log打印方法,log名换为LCLog // 2.定义一个宏obje ...

  10. [BZOJ 3823]定情信物

    题面 定情信物 题解 这题主要考高中物理和数学. 首先定义 \(f[i][j]\) 表示 \(i\) 维超立方体中第 \(j\) 维元素的数量,根据实际意义,我们可以推出递推式: \(f[i][j]= ...