早教吧 育儿知识 作业答案 考试题库 百科 知识分享

用一元五角人民币兑换五分,两分和一分的硬币,每一种方案里硬币总数不能超过一百枚,问共有几种兑换方案?

题目详情
用一元五角人民币兑换五分,两分和一分的硬币,每一种方案里硬币总数不能超过一百枚,问共有几种兑换方案?
▼优质解答
答案和解析
一共848种方案
C++源码如下:
int total = 150;
int coin5 = 5;
int coin2 = 2;
int coin1 = 1;
int combinations = 0;
int count5 = (total/coin5);
for(; count5 >= 0; count5--)
{
int count2 = ((total - count5 * coin5)/coin2);
for(;count2 >= 0;count2--)
{
int count1 = (total - count5 * coin5 - count2 * coin2);
if((count1 + count2 + count5)