the so-called greedy means always find the biggest, in solving problems, always make the best choice, it is the local optimal solution, not all problems can get the overall optimal solution. It has two important sub-properties:
1, the optimal sub-structure: if the sub-structure is removed, the remaining sub-structure is the optimal sub-structure. 2, greedy selectivity: Find the largest unit value of the one.
Focus: To solve its unit value (unit distance, etc.) for a series of problems, according to its unit value from large to small (from small to large) sequence. The greedy algorithm only needs to be taken in turn. For the lack of parts can be divided, to find part of the value.
example: Like a knapsack problem, the maximum value of a backpack weighs no more than 100. (w denotes item weight, v denotes value, v/w represents unit weight value, order is already lined up, as in the table below)
according to the above steps, you just need to follow the sequence of the order to take out in the package, such as the total weight of 90 items, Its value and is 115. There is a weight of 10 not installed, then only need to split the item 4 weight 10 to take care to get the maximum value: v=65+20+30+ (40/50) *60=163.
Summary:
to do greedy algorithm, it is important to note the following two points:
1, the unit value of each item from the big to the small sort
2. individual items can be divided into calculated value
Greedy algorithm of algorithm