母函数的应用

来源:互联网 发布:软件测试案例分析 编辑:程序博客网 时间:2024/06/11 21:57
 
#include <iostream>#include <string>#include <algorithm>using namespace std;// hdu 1028 Ignatius and the Princess IIIint c1[121],c2[121];int main(int argc, char **argv) {//freopen("input.txt","r",stdin);int i,j,k,n;while(cin>>n){//初始工作for(i=0;i<=n;++i){c1[i]=1;c2[i]=0;}// i代表多项式的个数for(i=2;i<=n;++i){for(j=0;j<=n;++j)// 对应于前(i-1)个多项式的x^j项for(k=0;k+j<=n;k+=i){ // 对应于第i个多项式的x^k项c2[k+j]+=c1[j]; // 乘法后x^(j+k)的系数放入c2[j+k]中}for(j=0;j<=n;++j){c1[j]=c2[j];c2[j]=0;}}cout<<c1[n]<<endl;}return 0;}

其对应的母函数为: