設有5種硬幣:1, 5, 6, 7, 15:找零50元使用最少數量的硬幣 | ||||||
先設定1~50中只需要1個及2個硬幣的數額;1個:1, 5, 6, 7, 15 | ||||||
2個:2{1+1},8{1+7},16{1+15},10{5+5},11{5+6},12{5+7}, 20{5+15},13{6+7},21{6+15},14{7+7},22{7+15},30{15+15} |
||||||
數值 | 硬幣數 | 數值 | 硬幣數 | 數值 | 硬幣數 | |
1 | 1 | 18 | 3 | 35 | 3 | |
2 | 2 | 19 | 3 | 36 | 3 | |
3 | 3 | 20 | 2 | 37 | 3 | |
4 | 21 | 2 | 38 | |||
5 | 1 | 22 | 2 | 39 | ||
6 | 1 | 23 | 3 | 40 | ||
7 | 1 | 24 | 41 | |||
8 | 2 | 25 | 3 | 42 | ||
9 | 3 | 26 | 3 | 43 | ||
10 | 2 | 27 | 3 | 44 | ||
11 | 2 | 28 | 3 | 45 | 3 | |
12 | 2 | 29 | 3 | 46 | ||
13 | 2 | 30 | 2 | 47 | ||
14 | 2 | 31 | 3 | 48 | ||
15 | 1 | 32 | 49 | |||
16 | 2 | 33 | 50 | |||
17 | 3 | 34 | 51 | |||
(50)=min{ (1)+(49) , (5)+(45) , (6)+(44) , (7)+(43) , (15)+(35)} = (5)+(45)或 (15)+(35) = 1+3 | ||||||
(45)=min{ (1)+(44) , (5)+(40) , (6)+(39) , (7)+(38) , (15)+(30)} = (15)+(30) = 1+2 | ||||||
(35)=min{ (1)+(34) , (5)+(30) , (6)+(29) , (7)+(28) , (15)+(20)} = (5)+(30)或(15)+(20) = 1+2 | ||||||
0 意見:
張貼留言