โ† Competitive Programming learning path
Competitive Programming ยท Module 8 of 10

Dynamic programming

Store answers to overlapping subproblems.

๐Ÿ“– Key ideas

  1. DP = recursion + memory: solve each subproblem once.
  2. Define the state, the transition and the base case.
  3. Top-down uses memoisation; bottom-up fills a table.
  4. Classics: Fibonacci, 0/1 knapsack, LIS, LCS, coin change.
  5. Complexity = number of states x work per state.
๐Ÿ’ก Real-life example: DP is writing answers in a notebook so you never solve the same homework question twice.
StateParameters describing a subproblem
TransitionHow a state uses smaller states
MemoisationCaching recursive results
TabulationBottom-up table filling