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, 6, 12, 16, 17, 19, 21, 23. What is the maximum revenue?

  1. A. 32
  2. B. 30
  3. C. 23
  4. D. 33

Correct answer: A. 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 30.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic