Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 C
A rod of length 8 can be cut into integer pieces. A piece of length i sells for price[i], where price = [0, 1, 5, 8, 9, 10, 17, 17, 20] (index = length). What is the maximum revenue from cutting the rod into any number of pieces?
- A. 22
- B. 20
- C. 18
- D. 21
Correct answer: A. 22
This is unbounded knapsack: best[i] = max over first piece j of price[j] + best[i − j]. Cutting into equal pieces is a restriction; splitting into unequal pieces such as 2 + 6 can beat every equal split.
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
- In how many ways can 12 be written as a sum of DISTINCT positive integers, where order does not matter (so 12 itself counts as one way)?
- Balloons with values [3, 1, 5, 8, 2] are burst one at a time. Bursting balloon i gives coins = left × value[i] × right, where left and…
- How many non-empty contiguous subarrays of [4, -2, 7, -5, 3, 6] have a sum of at most 4?
- Starting from n = 191, in each step you may replace n by n/2 when n is even, or by n−1 or n+1 when n is odd. What is the minimum number of…
- Coins of value 2, 3 and 5 are available in unlimited supply. In how many ways can you pay exactly 10 when the ORDER of coins does NOT…
- In the binary array [1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1] you may flip at most ONE 0 to a 1. What is the length of the longest run of…