Weighted Interval Scheduling by Prefix DP
Find the compatible predecessor of each interval and derive a recurrence that compares taking and skipping it.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Sort by the boundary future decisions need
Sort half-open intervals by finish time. Let \(p(j)\) be the last earlier interval ending no later than interval \(j\) starts, or zero if there is none. Every schedule choosing \(j\) uses only earlier intervals in the prefix through \(p(j)\). A schedule excluding it uses at most the first \(j-1\) intervals. With interval value \(w_j\), initialize \(D_0=0\) and compute
\[ D_j=\max(D_{j-1},w_j+D_{p(j)}). \]
Recover a schedule as well as its value
Taking \(j\) moves reconstruction to \(p(j)\). Skipping moves to \(j-1\). For values \(1,1,5\) on \([0,1),[1,2),[0,2)\), the comparison chooses the long interval even though two short intervals fit. This is where the unweighted exchange proof loses its premise. A boundary search for \(p(j)\) uses the binary-search invariant. With presorted predecessors, evaluating the recurrence itself is linear.[1][2]