ways[0] = 1; for t = 1..target, for each x ≤ t: ways[t] += ways[t − x].
Approach 1
class Solution {
public int combinationSum4(int[] nums, int target) {
int[] ways = new int[target + 1];
ways[0] = 1;
for (int t = 1; t <= target; t++)
for (int x : nums) if (x <= t) ways[t] += ways[t - x];
return ways[target];
}
}
Verdict: Like Climbing Stairs with arbitrary step sizes.