整数划分问题 hdu 1028(母函数)

http://acm.hdu.edu.cn/showproblem.php?pid=1028

母函数求解整数划分问题让我第一次感到了数学分析的作用,数学一定要学好,他会成为你ACM的一把利剑,披荆斩棘!!!

#include <stdio.h>
#define Maxn 40007

int c1[Maxn],c2[Maxn];
int main()
{
    int n,i;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=0;i<=n;i++)
        {
            c1[i]=1;
            c2[i]=0;
        }
        for(i=2;i<=n;i++)
        {
            for(int j=0;j<=n;j++)
            {
                for(int k=0;j+k<=n;k+=i)
                {
                    c2[j+k]+=c1[j];
                }
            }
            for(int j=0;j<=n;j++)
            {
                c1[j]=c2[j];
                c2[j]=0;
            }
        }

        printf("%d
",c1[n]);
    }
}

学习网址

http://www.tuicool.com/articles/bi6bei

http://www.tuicool.com/articles/Yba6jq

原文地址:https://www.cnblogs.com/ccccnzb/p/3439350.html