Data Structures & AlgorithmsHardGATE CS · Product-company placement

A rod of length 8 can be cut into integer pieces; a piece of length i sells for p(i) with p(1..8) = 2, 4, 15, 18, 19, 23, 24, 29. What is the maximum revenue?

  1. A. 34
  2. B. 29
  3. C. 37
  4. D. 36

Correct answer: D. 36

r(j) = max over first piece i of p(i) + r(j − i); r(8) = 36. Repeatedly cutting the best price-per-length piece (greedy) gives only 34.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic