This preview shows page 1. Sign up to view the full content.
Unformatted text preview: ck problem
a Given a knapsack with maximum capacity W, and
a set S consisting of n items a Each item i has some weight wi and benefit value vi
Each a Problem: How to pack the knapsack to achieve
maximum total value of packed items?
maximum Design and Analysis of Algorithms – Chapter 3 51 0-1 Knapsack problem: a picture
Weight vi 2
4 4 5
8 9 This is a knapsack
Max weight: W = 20 wi 5 Items W = 20 Benefit value 10 Design and Analysis of Algorithms – Chapter 3 52 0-1 Knapsack problem
a Problem, in other words, is to find max ∑ vi subject to
i∈T a a ∑w ≤W
i∈T i The problem is called a “0-1” problem,
because each item must be entirely accepted or
In the “Fractional Knapsack Problem,” we can
take fractions of items.
Design and Analysis of Algorithms – Chapter 3 53 0-1 Knapsack problem: brute-force
approach Let’s first solve this problem with a
a We go through all combinations (subsets) and
find the one with maximum value and with
total weight less or equal to W Design and Analysis of Algorithms – Chapter 3 54 Example 2: Knapsack Problem
Given n items:
• weights: w1 w2 … wn
• values: v1 v2 … vn
• a knapsack of capacity W
View Full Document
This note was uploaded on 10/31/2013 for the course RAIK 283 taught by Professor Yinglu during the Fall '12 term at UNL.
- Fall '12