Coin Change Problem

本文探讨了硬币兑换问题的最优解法,通过动态规划算法解决了该问题。详细介绍了贪婪算法的局限性,并阐述了动态规划在解决此类问题时的优势。通过实例分析,展示了如何使用动态规划来实现硬币兑换的最小数量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Given  N  denominations,how can a given amount of money  V  be made with the least number of coins? The most intuitive solution is greedy algorithm: sort the denominations, try the largest denominations lower than the value every time, and decrease the value with the denominations picked in every iteration. Repeat this process until the value reduces to 0. This greedy strategy works for the US (and most other) coin systems, However, it is not a general solution to all denomincations. For example, if the coin denominations were 1, 3 and 4, then to make 6, the greedy algorithm would choose three coins (4,1,1) whereas the optimal solution is two coins (3,3).

Actually the change-making problem is a knapsack type problem, which can be solved efficiently by Dynamic Programming.

- See more at: http://bo-yang.github.io/2014/06/20/coin-change/#sthash.m2CdaXkq.dpuf

http://bo-yang.github.io/2014/06/20/coin-change

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值