{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

06 - Dynamic Programming Design and Analysis of Algorithms...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Dynamic Programming Design and Analysis of Algorithms Andrei Bulatov
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Algorithms – Dynamic Programming 6-2 Knapsack The Knapsack Problem Instance : A set of n objects, each of which has a positive integer value and a positive integer weight . A weight limit W. Objective : i v i w Select objects so that their total weight does not exceed W, and they have maximal total value
Background image of page 2
Algorithms – Dynamic Programming 6-3 Idea A simple question: Should we include the last object into selection? Let OPT(n,W) denote the maximal value of a selection of objects out of {1, …, n} such that the total weight of the selection doesn’t exceed W More general, OPT(i,U) denote the maximal value of a selection of objects out of {1, …, i} such that the total weight of the selection doesn’t exceed U Then OPT(n,W) = max{ OPT(n – 1, W), OPT(n – 1, W – ) + } i w i v
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Algorithms – Dynamic Programming 6-4 Algorithm (First Try) Knapsack(n,W) set V1:=Knapsack(n-1,W) set V2:=Knapsack(n-1,W- ) output max(V1,V2+ ) Is it good enough?
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}