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

匿名 (未验证) 提交于 2019-12-03 00:41:02

传送门:

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

钱币兑换问题





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; }

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!