Minimum Cost to Cut a Stick
A wooden stick of length n has marked cut positions given in the array cuts. You may perform the cuts in any order; the cost of a single cut equals the current length of the stick being cut. After a cut, the stick splits into two pieces that are cut independently. Return the minimum total cost to perform all the cuts.
Open official problem prompt ↗Order the cuts to minimize total cost, where each cut costs the length of the segment it lands in at the time it is made.
Chopping a long baguette at marked spots where every chop costs effort proportional to the piece you are holding: you want to make big pieces smaller early in a balanced way so later chops are cheap.
- Input
- n = 7, cuts = [1, 3, 4, 5]
- Output
- 16
- Why
- Ordering cuts as 3,5,1,4 (or any optimal order) yields total cost 16; e.g. first cut costs 7, then the pieces cost less as they shrink.
2 <= n <= 10^61 <= cuts.length <= min(n - 1, 100)1 <= cuts[i] <= n - 1All cuts are distinct