Dynamic Programming Assignment | Homework For You
February 17th, 2020
3. Read the Discrete Knapsack Problem in the handout on Dynamic Programming. A thief wishes to steal n objects having values vi > 0 and weights Wi > 0 (for 1 sis n). His knapsack, which will carry the stolen goods, holds at most a total weight W > 0. Let Xi = 1 if object i is to be taken, and Xi = 0 if object i is not taken (1 Sisn). The thief’s goal is to maximize the total value x1=1 XiVi of the goods stolen, subject to the constraint X1=1 XiW; <W.
a. Write pseudo-code for a dynamic programming algorithm that solves this problem. Your algorithm should take as input the value and weight arrays v[] and w[], and the weight limit W. It should generate a table V[1 … n; 0 … W] of intermediate results. Each entry V[i, j] will be the maximum value of the objects that can be stolen if the weight limit is j, and if we only include objects in the set {1, …, i}. Your algorithm should return the maximum possible value of the goods which can be stolen from the full set of objects, i.e. the value V [n, W]. (Alternatively you may write your algorithm to return the whole table.)

b. Write an algorithm that, given the filled table generated in part (a), prints out a list of exactly which objects are to be stolen. Get Finance homework help today