G(x)=(1+x+x2+x3+x4+…)(1+x4+x8+x12+…)(1+x9+x18+x27+…)…
类似于这样的多项式,就是母函数
HDOJ_1398 Square Coins
HDOJ_1028
Ignatius and thePrincess III
等等
模版化代码:
等等
模版化代码:
#include <iostream>
using namespace std;
const int lmax=10000;
int c1[lmax+1],c2[lmax+1];
int main()
{ int n,i,j,k;
while (cin>>n)
{for (i=0;i<=n;i++)
{c1[i]=0; c2[i]=0; }
for (i=0;i<=n;i++) c1[i]=1;
for (i=2;i<=n;i++)
{ for (j=0;j<=n;j++)
for (k=0;k+j<=n;k+=i)
{ c2[j+k]+=c1[j]; }
for (j=0;j<=n;j++)
{ c1[j]=c2[j]; c2[j]=0; }
}
cout<<c1[n]<<endl;
}
return 0;
}
许多题目在此基础上稍加改动即可