HDU 1028 Ignatius and the Princess III(母函数)

题目链接:Click here~~

母函数第二题,整数划分。

#include 
#include 
const int MAX=120;
int main()
{
    int n,c1[MAX+5],c2[MAX+5];
    while(~scanf("%d",&n))
    {
        memset(c1,0,sizeof(c1));
        memset(c2,0,sizeof(c2));
        c1[0]=1;
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<=n;j++)
            {
                for(int k=0;j+k*i<=n;k++)
                {
                    c2[j+k*i] += c1[j];
                }
            }
            memcpy(c1,c2,sizeof(c2));
            memset(c2,0,sizeof(c2));
        }
        printf("%d\n",c1[n]);
    }
    return 0;
}


你可能感兴趣的:(HDU 1028 Ignatius and the Princess III(母函数))