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

589

被折叠的 条评论
为什么被折叠?



