钱币兑换问题

在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法。请你编程序计算出共有多少种兑法。

Input
每行只有一个正整数N,N小于32768。

Output
对应每个输入,输出兑换方法数。

Sample Input
2934
12553

Sample Output
718831
13137761

问题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1284
问题简述:输入总钱数,只有1、2、3的货币,求有多少种兑换方法。
问题分析:3最大,可以用3来分开钱数,1来补值,2来求取种数。
程序说明:while循环输入,for循环求3的数量逐渐减少1时,有多少种兑换方法,将其累加。
AC通过的C++程序如下:

include

using namespace std;
int main()
{
int a,b,n,sign=1;
while (cin >> n)
{
a = n / 3;
sign += a;
for (int i = 0; i <= n / 3; i++)
{
b = (n - 3 * i) / 2;
sign += b;
}
cout << sign << endl;
sign = 1;
}
return 0;
}

你可能感兴趣的:(钱币兑换问题)