Skip to main content

Minimum-Cost Merging

Challenge on lesson: Checkpoint — Merging

CHALLENGE
Difficulty: advanced+25 XP

**Problem.** Line 1: n. Line 2: n pile sizes in row order. Merging two ADJACENT piles costs their total size; make one pile with minimum total cost. **Constraints:** 1 ≤ n ≤ 500; 1 ≤ a[i] ≤ 10^6. Interval DP with prefix sums: O(n^3) is fine at n = 500.

Back to lesson: Checkpoint — Merging