纸币面额情况:1角、5角、1元、5元、10元、20元、50元、100元,每种面额的纸币的数量都是无限的。
int get_count(int money,int numcoins) {
int coins[8]={1,5,10,50,100,200,500,1000};
int firstcoin=coins[8-numcoins];
if(!money) {
return 1;
}
else if(money<0) {
return 0;
}
if(!numcoins) {
return 0;
}
return get_count(money-firstcoin,numcoins)+get_count(money,numcoins-1);
}
我还没有学过算法课,但是这样写会超时,过不了,请问有什么好的方法吗?
谢谢!!