Data Structures & AlgorithmsHardGATE CS

A rod of length 8 can be cut into integer pieces; a piece of length i sells for p(i) with p(1..8) = 1, 2, 5, 14, 16, 22, 24, 25. What is the maximum revenue?

  1. A. 28
  2. B. 24
  3. C. 25
  4. D. 29

Correct answer: A. 28

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic