贪心算法之找零钱
def greedy_change(amount, coins): coins.sort(reverse=True) # 将硬币按面额从大到小排序 change = [] for coin in coins: while amount >= coin: amount -= coin change.append(coin) # 将硬币加入到找零列表中 return change s = greedy_change(10,[1,2,3]) print(s)
全世界的程序员们联合起来吧!