hdu1028 Ignatius and the Princess III

这是道典型的母函数的题目,可以看看我的母函数这一标签上的另一道例题,里面对母函数做了较为详细的总结。这题仅贴上代码:

#include"iostream"
 2  using namespace std;
 3  #define  N 130
 4  int a[N+1],b[N+1];
 5  int main()
 6 {
 7     int n,i,j,k;
 8     while(cin>>n&&n!=0)
 9     {
10         for(i=0;i<=n;i++)
11         {a[i]=1;b[i]=0;}
12         for(i=2;i<=n;i++)
13         {
14             for(j=0;j<=n;j++)
15                 for(k=0;k+j<=n;k+=i)
16                 {
17                     b[k+j]+=a[j];
18                 }
19                 for(j=0;j<=n;j++)
20                 {
21                     a[j]=b[j];b[j]=0;
22                 }
23         }
24         cout<<a[n]<<endl;
25     }
26     return 0;
27     
28 }
原文地址:https://www.cnblogs.com/acm-jing/p/4253735.html