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

HDU 1284 钱币兑换问题(普通型 数量无限的母函数)

时间:2018-07-17 23:20:05      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:strong   ace   The   des   miss   合数   组合数   pid   style   

传送门:

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\n",c1[x]);
    }
    return 0;
}

 

 

HDU 1284 钱币兑换问题(普通型 数量无限的母函数)

标签:strong   ace   The   des   miss   合数   组合数   pid   style   

原文地址:https://www.cnblogs.com/yinbiao/p/9326254.html

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