Data Structures & AlgorithmsVery hardICPC regional · GATE CS

A stick of length 9 must be cut at the positions [5, 1, 7, 3]. A cut costs the current length of the stick piece it splits, and the cuts may be performed in any order. What is the minimum total cost?

  1. A. 27
  2. B. 21
  3. C. 23
  4. D. 16

Correct answer: B. 21

Add the endpoints 0 and n, then use interval DP: the first cut inside a segment (l, r) costs r − l and splits it into two independent problems. Making the cheapest cut first is a greedy trap.

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

Exams that ask this topic