[ACM] 几道母函数题目 hdu 1028 1398 1085

286 篇文章 140 订阅
41 篇文章 0 订阅
/*
//hdu 1028
//(1+x+x^2+x^3...) * (1+x^2+x^4+x^6....)  *  (1+x^3+x^6+x^9.....)*(1+x^4+x^8+x^12.....)*......
#include <iostream>
#include <string.h>
using namespace std;
const int maxn=122;
int temp[maxn];
int c[maxn];
int n;

int main()
{
    while(cin>>n)
    {
        for(int i=0;i<=n;i++)
        {
            temp[i]=0;
            c[i]=1;
        }//第一项
        for(int i=2;i<=n;i++)//第几个式子
        {
            for(int j=0;j<=n;j++)//原来式子的指数
                for(int k=0;k+j<=n;k+=i)//当前式子的指数
                    temp[k+j]+=c[j];//指数相乘,原来系数保留,因为当前式子所有的指数的系数都为1
            for(int i=0;i<=n;i++)
            {
                c[i]=temp[i];
                temp[i]=0;
            }
        }
        cout<<c[n]<<endl;
    }
    return 0;
}
*/

/*
//hdu 1398
//母函数为 (1+x+x^2+x^3+x^4...) * (1+x^4+x^8+x^12+x^16...) *(1+x^9+x^18+x^27...) * ...*(1+x^289+x^(289*2)+...)
#include <iostream>
using namespace std;
const int maxn=310;
int c[maxn];
int temp[maxn];
int n;

int main()
{
    while(cin>>n&&n)
    {
        for(int i=0;i<=n;i++)
        {
            c[i]=1;
            temp[i]=0;
        }
        for(int i=2;i*i<=n;i++)
        {
            for(int j=0;j<=n;j++)
                for(int k=0;k+j<=n;k+=i*i)
                temp[k+j]+=c[j];
            for(int j=0;j<=n;j++)
            {
                c[j]=temp[j];
                temp[j]=0;
            }
        }
        cout<<c[n]<<endl;
    }
    return 0;
}
*/

/*
//hdu 1085
//(1+x +x^2+x^3+..x^num1)  *(  1+x^2+x^4+x^6+.....x^num2) *( 1+x^5+x^10+x^15+....x^num5),只有三项
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
const int maxn=8100;
int temp[maxn];
int c[maxn];
int num[6];

int main()
{
    while(cin>>num[1]>>num[2]>>num[3]&&(num[1]||num[2]||num[3]))
    {
        int MAX=num[1]+2*num[2]+5*num[3];//最大指数
        memset(c,0,sizeof(c));
        for(int i=0;i<=num[1];i++)
            c[i]=1;
        for(int i=2;i<=3;i++)
        {
            memset(temp,0,sizeof(temp));
            for(int j=0;j<=MAX;j++)
                for(int k=0;k<=num[i];k++)
                {
                    if(i==2)
                        temp[j+k*2]+=c[j];
                    else
                        temp[j+k*5]+=c[j];
                }
            for(int i=0;i<=MAX;i++)
                c[i]=temp[i];
        }
        bool ok=1;
        for(int i=0;i<=MAX;i++)
            if(c[i]==0)
            {
                ok=0;
                cout<<i<<endl;
                break;
            }
        if(ok)
            cout<<MAX+1<<endl;
    }
    return 0;
}
*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值