Mid-II-2a-sol

# Mid-II-2a-sol - Midterm II, Part 2 Version A Solution Nov....

This preview shows pages 1–3. Sign up to view the full content.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Midterm II, Part 2 Version A Solution Nov. 18, 2011 2:00pm - 2:50pm CS431 CS531 (Please circle one) First Name (Print): Last Name (Print): UB ID number: 1. This is a closed book, closed notes exam. 2. You must support your answer. 3. If you need more space, use the back side of the pages. 4. Write your name on the top right-hand corner of every page. 5. There are 3 problems and 8 points for each. DO ONLY TWO of the THREE prob- lems. So the maximum points of this part of the exam is 16. 6. Clearly circle the problems you want to be graded. If you dont, the first two problems will be graded. 5 6 7 Name 5. (8 points) The 0/1-Knapsack Problem is defined as: We are given n items . Each item i has a weight w [ i ] and a profit p [ i ]. (There is ONLY ONE item i , for each 1 i n ). We also have a Knapsack with capacity K . The goal is to choose a subset of items so that: The total weigh of the selected items is at most K ; and the total profit of the selected items is maximum. The problem can be solved by dynamic programming by using the following formula: Profit[ i ][ j ] = if i = 0 (1) if j = 0 (2) Profit[ i 1][ j ] if i negationslash = 0, j negationslash = 0 and w [ i ] > j (3) max { (4 a ) bracehtipdownleft bracehtipuprightbracehtipupleft bracehtipdownright Profit[ i 1][ j ] , p [ i ] + Profit[ i 1][ j w [ i ]] bracehtipupleft bracehtipdownrightbracehtipdownleft...
View Full Document

## This note was uploaded on 02/27/2012 for the course CSE 431/531 taught by Professor Xinhe during the Fall '11 term at SUNY Buffalo.

### Page1 / 4

Mid-II-2a-sol - Midterm II, Part 2 Version A Solution Nov....

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

View Full Document
Ask a homework question - tutors are online