首页 > 代码库 > 母函数hdu1085

母函数hdu1085

直接来。(1+x+x^2...+)*(1+x^2+x^4+....)*(1+x^5+x^10+...)

求系数的模板 

        c[0]=1;        for(int i = 0 ;i<3;i++){            for(int j= 0 ;j<= a[i];j++)            for(int k = 0 ;k+j*val[i]<=Max;k++){                c1[k+j*val[i]]+=c[k];            }            for(int k =0 ;k<=Max;k++)                c[k]=c1[k],c1[k]=0;        }

 

#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <climits>#include <string>#include <iostream>#include <map>#include <cstdlib>#include <list>#include <set>#include <queue>#include <stack>using namespace std;int a[10];int val[]={1,2,5};int c[111111];int c1[111111];int main(){    while(scanf("%d%d%d",&a[0],&a[1],&a[2])!=EOF,a[0]+a[1]+a[2]){        int Max =  val[0] *a[0]+val[1]*a[1]+val[2]*a[2];        memset(c1,0,sizeof(c1));memset(c,0,sizeof(c));        for(int i = 0 ;i<=a[0];i++)            c[i] = 1;        for(int i = 1 ;i<3;i++){            for(int j= 0 ;j<= a[i];j++)            for(int k = 0 ;k+j*val[i]<=Max;k++){                c1[k+j*val[i]]+=c[k];            }            for(int k =0 ;k<=Max;k++)                c[k]=c1[k],c1[k]=0;        }        int ans=0 ;        for(int i =0 ;i<=Max+100;i++)            if(!c[i]){                ans=i;break;            }        printf("%d\n",ans);    }    return 0;}