Change-making problem

来源:互联网 发布:中国材料数据库 编辑:程序博客网 时间:2024/04/30 14:53

http://en.wikipedia.org/wiki/Change-making_problem

 

Given unlimited amounts of coins of denominations d1 > … > dm , must contain 1.
give change for amount n with the least number of coins.
Does the greedy algorithm always give an optimal solution for the general change-making
problem We give the following example,
Example: d1 = 7c, d2 =5c, d3 = 1c, and n = 10c, not always produces an optimal solution. in fact, for some instances, the
problem may not have a solution at all! consider instance d1 = 7c, d2 =5c, d3 = 3c, and n = 11c.
But, this
problem can be solved by dynamic programming, please try to design an algorithm for the general Change-making_problem after class.


该算法复杂度为O(NK)

 

 

 

 

 

原创粉丝点击