a4_solution

a4_solution - CS325 Winter 2013 HW4 Due Feb 22nd in class 1...

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

View Full Document Right Arrow Icon
CS325 Winter 2013: HW4 Due Feb 22nd in class 1. Knapsack without repetitions. Consider the following knapsack problem: The total weight limit W = 10 and Item Weight Value 1 6 $30 2 3 $14 3 4 $16 4 2 $9 Solve this problem using the dynamic programming algorithm presented in class. Please show the two dimensional table L ( w,j ) for w = 0 , 1 ,...,W and j = 1 , 2 , 3 , 4. L 0 1 2 3 4 5 6 7 8 9 10 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 30 30 30 30 30 2 0 0 0 14 14 14 30 30 30 44 44 3 0 0 0 14 16 16 30 30 30 44 46 4 0 0 9 14 16 23 30 30 39 44 46 2. Give a dynamic programming algorithm for solving the following problem. Input: A list of n positive integers a 1 ,a 2 ,...,a n and a number t . Goal: Decide if some subset of the a i ’s add up to t . (You can use each a i at most once.) The running time should be O ( nt ). Consider the subproblem L ( i,s ), which returns the answer of “Does a subset of a 1 i sum up to s ?”. Below are some substeps that will help you develop your algorithm. a What are the two options we have regarding item i toward answering the subproblem L ( )?
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
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 3

a4_solution - CS325 Winter 2013 HW4 Due Feb 22nd in class 1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online