# [leetcode] 377.Combination Sum IV

Example:

nums = [1, 2, 3]
target = 4

The possible combination ways are:
(1, 1, 1, 1)
(1, 1, 2)
(1, 2, 1)
(1, 3)
(2, 1, 1)
(2, 2)
(3, 1)

Note that different sequences are counted as different combinations.

Therefore the output is 7.

What if negative numbers are allowed in the given array?
How does it change the problem?
What limitation we need to add to the question to allow negative numbers?

（比如题目中的例子[1，2，3]

dp[1] = dp[1]+dp[0] = 1;

dp[2] = dp[2]+dp[1] = 1;

dp[2] = dp[2]+dp[0] = 2;

….
…..
….）

public class Solution {
public int combinationSum4(int[] nums, int target) {
int result  = 0;

int[] dp = new int[target+1];
dp[0] = 1;

for(int i = 1; i < target + 1; i++) {
for (int num : nums) {
if(i >= num){
dp[i] = dp[i] + dp[i - num];
}else{
break;
}
}
}

result = dp[target];
return result;
}
}

#### leetcode 416. Partition Equal Subset Sum 动态规划DP + 深度优先遍历DFS

2017-12-08 16:03:13

#### 【LeetCode】377. Combination Sum IV 解题报告

2018-02-21 19:15:41

#### leetcode 801.Minimum Swaps To Make Sequences Increasing

2018-03-19 22:23:30

#### 360笔试遇到的博弈问题（DP）

2017-03-19 10:27:03

#### Leetcode 416. Partition Equal Subset Sum 对半分 解题报告【修正版】

2016-10-09 13:24:43

#### [leetcode] 377. Combination Sum IV 解题报告

2016-07-29 14:08:17

#### leetcode 377. Combination Sum IV 换钱问题

2017-06-09 16:48:47

#### Combination Sum IV - leetcode 377号题目个人题解

2016-11-20 20:29:47

#### LeetCode—377. Combination Sum IV

2016-07-25 12:08:55

#### leetcode 377. Combination Sum IV 解题报告

2016-08-04 21:39:31