Data Structures & AlgorithmsHardProduct-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, 8, 10, 13, 21, 22, 25, 28. What is the maximum revenue?

  1. A. 31
  2. B. 28
  3. C. 32
  4. D. 33

Correct answer: C. 32

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic