zoukankan      html  css  js  c++  java
  • HDU 1284 钱币兑换问题(普通型 数量无限的母函数)

    传送门:

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

    钱币兑换问题

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 12335    Accepted Submission(s): 7453


    Problem Description
    在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法。请你编程序计算出共有多少种兑法。
     
    Input
    每行只有一个正整数N,N小于32768。
     
    Output
    对应每个输入,输出兑换方法数。
     
    Sample Input
    2934 12553
     
    Sample Output
    718831 13137761
     
    Author
    SmallBeer(CML)
     
    Source
     
    分析:
    母函数分为两类
    普通型求组合数:数量有限普通型,数量无限普通型
    指数型求排列数
    本题:
    数量无限的普通型母函数:
    模板题
    自己对母函数的研究还很浅,只会套这种简单模板。。
    加油,多刷题
    code:
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define max_v 32768
    int c1[max_v];
    int c2[max_v];
    int main()
    {
        for(int i=0;i<max_v;i++)
        {
            c1[i]=1;
            c2[i]=0;
        }
        for(int i=2; i<=3; i++)
        {
            for(int j=0; j<max_v; j++)
            {
                for(int y=0; y+j<max_v; y+=i)
                {
                    c2[j+y]+=c1[j];
                }
            }
            for(int j=0; j<max_v; j++)
            {
                c1[j]=c2[j];
                c2[j]=0;
            }
        }
        int x;
        while(~scanf("%d",&x))
        {
            printf("%d
    ",c1[x]);
        }
        return 0;
    }
     
  • 相关阅读:
    python学习之路01
    面向对象(2)__继承多态1
    面向对象(1)____私有公有 访问限制
    property
    yield理解
    列表推导式
    Django序列化1_基本的序列化和反序列化
    一些滑动操作
    装饰器
    django模板
  • 原文地址:https://www.cnblogs.com/yinbiao/p/9326254.html
Copyright © 2011-2022 走看看