Dynamic Programming
Break problems into overlapping subproblems, cache results, and build up to the final answer.
- • Optimal substructure + overlapping subproblems
- • Counting ways
- • Min/max optimization
- • String matching
- • No overlapping subproblems (use divide and conquer)
- • Greedy works and is simpler
- • Wrong state definition
- • Wrong transition formula
- • Not initializing base cases
- • Off-by-one in table dimensions
Key Invariant
Define the state clearly, write the recurrence, then decide top-down (memo) or bottom-up (table)