Dynamic Programming21 sections · 916 units
Open in Course

IOI Aliens - DP Formulation

Without the trick

Let dp[i][j]dp[i][j] = minimum total area to cover the first ii points using exactly jj photos. Transition: dp[i][j]=minp<i(dp[p][j1]+squareArea(p+1,i)overlap(p,p+1))dp[i][j] = \min_{p < i}(dp[p][j-1] + squareArea(p+1, i) - overlap(p, p+1)). You cover points p+1p+1 through ii with one photo, add its area, and subtract the overlap with the previous photo. The overlap term handles double-counting when adjacent photos share cells.

This is critical for correctness. Without it, overlapping cells would be counted twice. Complexity: O(n2k)O(n^2 k). With n=100,000n = 100{,}000 and k=100,000k = 100{,}000, that's 101510^{15} operations. Completely infeasible.