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

时间:2022-05-14 00:21:31

传送门:

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=;i<max_v;i++)
{
c1[i]=;
c2[i]=;
}
for(int i=; i<=; i++)
{
for(int j=; j<max_v; j++)
{
for(int y=; y+j<max_v; y+=i)
{
c2[j+y]+=c1[j];
}
}
for(int j=; j<max_v; j++)
{
c1[j]=c2[j];
c2[j]=;
}
}
int x;
while(~scanf("%d",&x))
{
printf("%d\n",c1[x]);
}
return ;
}