Dynamic Programming21 sections · 916 units
Open in Course

The Insight

Penalty parameter

What if you stopped caring about exactly KK? Instead, add a penalty λ\lambda (lambda, a number you choose) for each segment you create. New goal: reduce (total cost + λ×\lambda \times segment count). Solve this for different λ\lambda values.

When λ=0\lambda = 0, you use as many segments as possible (no penalty). When λ\lambda is huge, you use few segments (they're expensive). Somewhere in between, you'll naturally use exactly KK segments. That's the trick.