Академический Документы
Профессиональный Документы
Культура Документы
Greedy Algorithms
A greedy algorithm always makes the choice that looks best at the moment
My everyday examples:
Taking Bus/Auto/Taxi to station
The hope: a locally optimal choice will lead to a globally optimal solution
Goal: Choose items with maximum total benefit but with weight at most W. If we are allowed to take fractional amounts, then this is the fractional knapsack problem.
In this case, we let xi denote the amount we take of item i Objective: maximize
b (x / w )
iS i i i i
Constraint:
x
iS
Example
Given: A set S of n items, with each item i having
bi - a positive benefit wi - a positive weight
Goal: Choose items with maximum total benefit but with weight at most W. knapsack Solution: Items: Weight: Benefit: Value:
($ per ml)
1 2 3 4 5
4 ml $12 3
8 ml $32 4
2 ml $40 20
6 ml $30 5
1 ml $50 50 10 ml
1 2 6 1
ml ml ml ml
of of of of
5 3 4 2