βœ… When to think DP?

  • Count total ways
  • Find minimum
  • Find maximum
  • β€œTry all possible choices”

Try all possible choices β†’ Recursion β†’ DP

  • We use it when greedy fails

πŸš€ 3-Step Trick

1. Define the State

Represent the problem using an index/state.

f(i) = Answer for state i

2. Find All Choices

List every possible move from that state.

Choice 1
Choice 2
...

3. Combine Results

  • Count ways β†’ +
  • Minimum β†’ min()
  • Maximum β†’ max()
  • Possible? β†’ || return true or return false

πŸ“Œ Climbing Stairs

State

f(i) = Ways to reach stair i

Choices

i-1
i-2

Combine

f(i) = f(i-1) + f(i-2)

Base Cases

f(0) = 1
f(i < 0) = 0

0 items under this folder.