主要填补知识漏洞:
一、母函数分析法
(1)普通母函数
在考虑“当投掷n粒骰子时,加起来点数总和等于m的可能方式的数目”这个问题时首先使用了母函数方法,并得出可能的数目是的展开式中
项的系数。
典型模型:砝码称重
特点:求某个解权重之和的解数
例题:有1,2,3g的砝码各一个,称出质量为3的砝码,有几种组合方法。
G(x)=(1+x)(1+x^2)(1+x^3) 答案是x^3的系数。因为幂函数相乘指数相加。
拓展:若是3种砝码有无数种
G(x)=(1+x+x^2+x^3+x^4....)(1+x^2+x^4+x^6....)(1+x^3+x^6+x^9...) 同样 答案是x^3的系数。
例题:HDU2082 http://acm.hdu.edu.cn/showproblem.php?pid=2082
AC代码:
1 /*HDU2082 2 普通型母函数 3 题目:假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26。那么,对于给定的字母,可以找到多少价值<=50的单词呢? 4 G(x)=(1+x+x^2+x^3...x^x1)(1+x^2+x^4+...x^(x2^2))(1+x^3....) 5 答案就是G(x)展开后的指数小于等于50的项的常数系数之和 6 */ 7 #include <cmath> 8 #include <algorithm> 9 #include <stdlib.h> 10 #include <iostream> 11 #include <string.h> 12 #include <stdio.h> 13 #include <stack> 14 #include <set> 15 #include <map> 16 #include <vector> 17 #define LL long long 18 #define maxn 77 19 using namespace std; 20 LL T; 21 LL a[maxn],b[maxn]; 22 23 int main(){ 24 cin>>T; 25 while(T--){ 26 memset(a,0,sizeof(a)); 27 memset(b,0,sizeof(b)); 28 a[0]=1; 29 for(int i=1;i<=26;i++){ 30 int t; 31 cin>>t; 32 if (t==0) continue; 33 for(int j=0;j<=50;j++){ 34 for(int k=0;k+j<=50 && k<=t*i;k+=i){ 35 b[j+k]+=a[j]*1; 36 } 37 } 38 for(int i=0;i<=50;i++) a[i]=b[i]; 39 memset(b,0,sizeof(b)); 40 } 41 LL ans=0; 42 for(int i=1;i<=50;i++) ans+=a[i];//注意x的下限 43 cout<<ans<<endl; 44 } 45 return 0; 46 }