Given distinct positive numbers, count the sequences (order matters) of them, with repetition, that sum to target.
Before you code
Despite the name, this counts orderings: 1 + 2 and 2 + 1 are different. That is decided entirely by which loop is outside.
Hints
dp[0] = 1.- Loop over totals t from 1 to target on the outside, and numbers on the inside:
dp[t] += dp[t - x]. - Swap the loops (numbers outside) and you count combinations instead, as in Coin change II.
Production & complexity notes
When solving Combination sum IV on LeetCode (medium), always state your loop or recursion invariant before writing code. Verify how your chosen data structure behaves on degenerate inputs (single-element inputs, all-duplicate keys, strictly monotonic sequences, or maximum constraint sizes up to $10^5$ elements). In production interviews, pair your implementation with an explicit time and auxiliary space complexity proof, explain why alternative brute-force approaches violate the latency budget, and trace how cache locality and memory allocation overhead affect wall-clock throughput on real hardware. Review the step-by-step memory trace in Knapsack and subsets to reinforce the underlying pattern.
What it practices
Loop order in counting knapsacks, from Knapsack and subsets.