CIS 435, Spring 2002, Jim CalvinHomework #10 Solutions16.2-3Suppose we havenitems with weightsw1≤w2≤ ··· ≤wnand valuesv1≥v2≥ ··· ≥vn. The optimal algorithm is: take items 1,2,... ,kwherekisthe frst integer such thatw1+w2+···+wk+1>L. To show that this is optimal,we frst show that an optimal solution contains item 1 (assuming thatL>w1). IFnot, replace any chosen item with 1 and the weight is no greater and the value isat least as high. Thus there is an optimal solution containing item 1. An optimalsolution to the subproblem with items 2 throughnmust contain item 2, and so on.16.2-4ProF. Midas should drive as Far as he can on each tank oF gas without
This is the end of the preview.
access the rest of the document.