Pattern: Dynamic Programming (1D DP) + Counting Permutations

Let's follow the same problem-solving template:

  1. Understand the problem through an example
  2. Signal — identify the pattern and constraints
  3. Edge cases
  4. Brute Force — Recursive Backtracking
  5. Optimized Solution — Dynamic Programming
  6. Dry Run — Visualize DP
  7. Complexity Analysis
  8. Interview explanation

1. Understand the problem through an example

Given:

Find the number of possible combinations that add up to target.

Important rule: The order of numbers matters.

For example:

nums = [1, 2, 3]target = 4

We need to find all possible ordered sequences whose sum equals 4.

All valid combinations