作者like9515 (包子小蕭)
看板b96902HW
標題[問題]關於助教課...
時間Fri Oct 19 00:01:13 2007
有一題是用10、5、1來湊成10有幾種方法
first try用的自訂函數寫法如下
int count(int target){
int total = 0;
if(target == 0)
return 1;
if(target >= 10)
total += count(target - 10);
if(target >= 5)
total += count(target - 5);
if(target >= 1)
total += count(target - 1);
return total;
}
但是會多算次數
後來助教有教怎麼改
我有點忘記了,有人還記得嗎?
懇請助教或強者解答~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 124.155.139.123