Dynamic Programming21 sections · 915 units
Open in Course

Pattern - CHT Recognition

When to apply CHT

Signal: dp[i]=min⁡j(dp[j]+f(i,j))dp[i] = \min_{j}(dp[j] + f(i, j)) where f(i,j)f(i, j) can be written as mj⋅g(i)+cj+h(i)m_j \cdot g(i) + c_j + h(i). The mj⋅g(i)m_j \cdot g(i) is the linear term. cjc_j is the intercept. h(i)h(i) is added after the query.

Common forms: aj⋅bia_j \cdot b_i, (a−b)2(a - b)^2 expanded, prefix sum products. Look for products of ii-term and jj-term. If you see a quadratic that expands into separable terms, CHT likely applies. Practice recognizing the pattern.