Dynamic Programming21 sections · 916 units
Open in Course

Covered Walkway - Problem Statement

Another classic

Cover nn points with roofs. Roof [l,r][l, r] costs c+(rl)2c + (r - l)^2. Find minimum total cost. dp[i]dp[i] = min cost to cover first ii points. Transition: dp[i]=minj<i(dp[j]+c+(xixj+1)2)dp[i] = \min_{j < i}(dp[j] + c + (x_i - x_{j+1})^2). Expand the square.

After algebra: dp[i]=min((2xj+1)xi+(dp[j]+c+xj+12))+xi2dp[i] = \min((-2x_{j+1}) \cdot x_i + (dp[j] + c + x_{j+1}^2)) + x_i^2. Lines have slope 2xj+1-2x_{j+1} and intercept dp[j]+c+xj+12dp[j] + c + x_{j+1}^2. Apply CHT. Add xi2x_i^2 to the query result.