Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

Items are given as (weight1, weight2, value): [(2, 3, 4), (3, 4, 5), (4, 6, 2), (1, 1, 1), (5, 7, 8)]. Each item can be used once. You need total weight1 ≤ 8 AND total weight2 ≤ 7. What is the maximum total value?

  1. A. 13
  2. B. 6
  3. C. 9
  4. D. 10

Correct answer: C. 9

A 2-dimensional knapsack adds a second capacity dimension to the dp table; each item updates dp[x][y] from dp[x − a1][y − a2]. Ignoring the second weight (keeping only the first constraint) can select a set that violates weight2.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic