Reprint Please specify source: http://www.cnblogs.com/StartoverX/p/4611544.html
The greedy algorithm makes the best-looking choice at the time of every step. In other words, it always makes local optimal choice, hoping (proving) that such a choice can lead to a global optimal solution.
Both greedy algorithm and dynamic programming depend on the optimal substructure , that is, the optimal solution of a problem contains the optimal solution of its sub-problem. The difference is that dynamic programming usually requires solving each sub-problem, and the solution to the problem is obtained by solving all the child problems. The greedy algorithm hopes to improve the optimal substructure by greedy selection, so that only one sub-problem is left after each selection , which greatly simplifies the problem solving process. So the problem of being able to use the greedy algorithm contains some special conditions that need to be carefully detected. The relationship between greedy algorithm and dynamic programming allows us to conclude that there is almost always a more tedious dynamic programming algorithm under each greedy algorithm.
The greedy algorithm steps:
1. Transform the optimization problem into this form: Once a selection has been made, only one sub-problem needs to be solved.
2. After proving the greedy choice, the original problem always has the optimal solution, that is, the greedy choice is always safe.
3. After proving the greedy choice, the remaining sub-problem satisfies the nature: the optimal solution of the original problem can be obtained by combining the optimum and greedy selection, and the optimal substructure is obtained.
Example: Leetcode Jump game:http://www.cnblogs.com/startoverx/p/4611518.html
[Introduction to Algorithms] greedy algorithm (greedy algorithm)