Competitive Programming

Dynamic Programming - Part 2

Step up from 1D DP to the state shapes that win mid-to-hard contest problems — two-sequence/grid DP, interval DP on [l..r], bitmask DP over subsets, digit DP for counting numbers, and DP on trees. Same recursive + memoization recipe from Part 1, richer states. Worked examples: LCS, edit distance, matrix chain, longest palindromic subsequence, TSP, digit-sum counting, and tree max-weight independent set.

Topics