Dynamic Programming21 sections · 916 units
Open in Course

Pattern - CHT Recognition

When to apply CHT

Signal: dp[i]=minj(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 mjg(i)+cj+h(i)m_j \cdot g(i) + c_j + h(i). The mjg(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: ajbia_j \cdot b_i, (ab)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.