码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-10-03 11:44:49      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:blog   io   os   for   sp   2014   c   log   amp   

///整数拆分模版
///g(x)=(1+x+x^2...)(1+x^2+x^4...)(1+x^3+x^6...)
# include<stdio.h>
# include<algorithm>
# include<string.h>
# include<iostream>
using namespace std;
int main()
{
    int n,i,j,k,c1[125],c2[125];
    while(~scanf("%d",&n))
    {
        ///初始化,对应第一个表达式(1+x+x^2....),这是i在(0,n)之间只有一种情况
        for(i=0;i<=n;i++)
        {
            c1[i]=1;///保存各个数字可以组合的数目
            c2[i]=0;///中间量,保存每一次的情况
        }
        ///从第二个表达式开始
        for(i=2;i<=n;i++)
        {
            for(j=0;j<=n;j++)///j从0到n枚举
            {
                for(k=0;k+j<=n;k+=i)///从k枚举第i个表达式的指数,第i个表达式的指数增量为i
                {
                    c2[k+j]+=c1[j];
                }
            }
            for(j=0;j<=n;j++)///把c2的值赋值给c1,因为每次c2都是从另一个表达式开始的
            {
                c1[j]=c2[j];
                c2[j]=0;
            }

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

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

标签:blog   io   os   for   sp   2014   c   log   amp   

原文地址:http://blog.csdn.net/lp_opai/article/details/39753979

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!