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

poj 1221 UNIMODAL PALINDROMIC DECOMPOSITIONS (母函数)

时间:2014-10-04 23:45:57      阅读:190      评论:0      收藏:0      [点我收藏+]

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

/*
给出一个数n,把它拆分成若干个数的和,要求最大的数在中间并向两边非递增。问拆法有多少种。

母函数。枚举中间的那一个数,因为左右对称,所以只需要求左边部分的方案即可。
注意,左右两部分的取数必须小于中间的数,中间的数是0的话则以n为最大取值。
*/
# include <stdio.h>
# include <algorithm>
# include <string.h>
# include <iostream>
typedef long long LL;
using namespace std;
LL c1[10010],c2[10010];
LL slove(LL m,LL n)
{

    for(int i=0; i<=n; i++)
    {
        c1[i]=1;
        c2[i]=0;
    }
    if(m==0)
        m=n;
    for(int i=2; i<=m; i++)
    {
        for(int j=0; j<=n; j++)
        {
            for(int k=0; k+j<=n; k+=i)
            {
                c2[k+j]+=c1[j];
            }
        }
        for(int j=0; j<=n; j++)
        {
            c1[j]=c2[j];
            c2[j]=0;
        }
    }
    return c1[n];
}
int main()
{
    int  n;
    LL ans;
    while(~scanf("%d",&n),n)
    {
        ans=0;
        for(int i=0;i<=n;i++)
        {
            if((n-i)%2==0)
               {
                   ans+=slove(i,(n-i)/2);
               }
        }
        printf("%d %lld\n",n,ans);
    }
    return 0;
}

poj 1221 UNIMODAL PALINDROMIC DECOMPOSITIONS (母函数)

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

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

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