思想: dp
状态转移方程:dp[i]=Σdp[i-nums[k]] 0<=k<=nums.length
代码:
public class Solution { public int combinationSum4(int[] nums, int target) { int len = nums.length; int[]dp = new int[target+1]; dp[0]=1; Arrays.sort(nums); for(int i =0;i<=target;i++){ for(int num: nums){ if(i<num) break; dp[i] = dp[i]+dp[i-num]; } } return dp[target]; } }