When to Use

Pattern triggers

Look for these signals in the problem:

  • "Count the number of ways": When counting paths, combinations, or arrangements, DP accumulates counts from smaller subproblems.
  • "Find minimum/maximum" over choices: When each step involves choosing from options, DP tracks optimal values for each state.
  • "Can you reach/achieve X": Boolean DP tracks reachability by combining reachability of earlier states.
  • Problem has optimal substructure: If optimal solution contains optimal solutions to subproblems, DP applies.
  • Overlapping subproblems visible: If naive recursion solves same subproblems repeatedly, DP eliminates redundancy.