算法与数据结构递归单选难度 3真题改编 · 2023
1958. 给定一组硬币面值 $C=\{1,5,10,25,60,100\}$ ,下面是用最少的硬币向客户支付金额的贪心算法,下列关于该贪心算法的叙述正确的是()
ALGORITHM (x, c1, c2, …, cn)//c1,c2..表示货币金额
SORT n coin denominations so that 0 < c1 < c2 < … < cn.
S ← ∅.//选择货币的集合
WHILE (x > 0)
k ← largest coin denomination ck such that ck <= x.
IF no such k, RETURN “no solution.”
ELSE
x ← x – ck.
S ← S ∪ { k }.
RETURN S.
练习本题 ›