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

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

时间:2015-02-01 16:08:54      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

题意:

  N=a[1]+a[2]+a[3]+...+a[m];
  a[i]>0,1<=m<=N;

例如:

  4 = 4;
  4 = 3 + 1;
  4 = 2 + 2;
  4 = 2 + 1 + 1;
  4 = 1 + 1 + 1 + 1;

共有5种。

给N,问共有几种构造方式。

 

思路:

一个数N分解的式子中1的个数可以是0,1,2,3,...,N。

2的个数可以是0,1,2,...,N/2。

....

母函数基础题,,

看代码。

当然也可以用DP(背包)

 

母函数代码:

int N,num;
int a[200],b[200];

int main(){
    while(cin>>N){
        memset(a,0,sizeof(a)); a[0]=1; memset(b,0,sizeof(b));
        for(int i=1;i<=N;++i){
            for(int j=0;j<=N;++j)
                for(int k=0;k+j<=N;k+=i) b[j+k]+=a[j];
            for(int j=0;j<=N;++j){ a[j]=b[j]; b[j]=0; }
        }
        cout<<a[N]<<endl;
    }
}

 

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

标签:

原文地址:http://www.cnblogs.com/fish7/p/4265605.html

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