Given an array of positive integers and a target sum, return the minimum number of elements needed to form exactly that sum using unlimited copies of the array elements. Return -1 if the sum cannot be formed. This is an unbounded-choice minimization DP.
nums = allowed values, x = target sum
minimum number of elements needed, or -1
Example 1:
Input:
nums = [1,4,5] x = 8
Output:
2
Explanation:
8 = 4 + 4.
Example 2:
Input:
nums = [4,6] x = 7
Output:
2
Explanation:
7 cannot be formed using 4 and 6.