Given an array of distinct positive integers and a target, return the number of ordered combinations that sum to the target. This is the classic iterate-order problem where changing loop order changes the result.
nums = distinct positive integers, target = required sum
number of ordered combinations that sum to target
Example 1:
Input:
nums = [1,2,3] target = 4
Output:
7
Explanation:
The ordered sequences are [1,1,1,1], [1,1,2], [1,2,1], [2,1,1], [2,2], [1,3], and [3,1].
Example 2:
Input:
nums = [9] target = 3
Output:
0
Explanation:
No ordered combination can sum to 3 using only 9.