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?
- A. 13
- B. 6
- C. 9
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many ways can the six numbers [1, 2, 3, 4, 5, 6] be assigned to three labelled groups (group A, group B, group C), each number going…
- From the numbers [1, 2, 3, 5, 6, 8, 9, 10], what is the size of the largest subset in which any two chosen numbers differ by at least 2?
- Starting at index 0 of the array [4, 8, 5, 2, 25], repeatedly jump to the next strictly greater element (a monotonic stack gives these…
- What is the sum of the stock span values for prices [100, 80, 60, 70, 60, 75, 85]? The span of day i is the number of consecutive days…
- A queue is built from two stacks: enqueue pushes onto the inbox stack, and dequeue pops from the outbox stack, first transferring all…
- How many non-empty distinct palindromic partitions, i.e. ways to split the string aabb into contiguous pieces where every piece is a…