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?

  1. A. 22
  2. B. 20
  3. C. 18
  4. 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.

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

Exams that ask this topic