第八章 贪心算法2016.ppt

heyichao@sjzue.edu.cn Greedy Algorithms ● Algorithms for optimization problems typically go through a sequence of steps, with a set of choices at each step. ● Greedy algorithm always makes the choice that looks best at the moment. ● Greedy algorithm makes a locally optimal choice in the hope that this choice will lead to a globally optimal solution. 找钱问题 找钱问题的贪心算法 输入:n种钱币集合S={m1, m2,...,mn}和面值vi,及要找钱数y; 输出: 使目标函数f(X)(钱币张数)达到最小值的钱币集合X。 1. 初始化解集X ← Φ,并计算f(X) ; 2. 按面值将S中的钱币降序排列; 3. 循环: i 从1 到 n , 且钱数还没找完, 做 4. [ 若 v

文档评论(0)

1亿VIP精品文档

相关文档