377. 组合总和 Ⅳ
为保证权益,题目请参考 377. 组合总和 Ⅳ(From LeetCode).
解决方案1
CPP
C++
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
class Solution
{
public:
int combinationSum4(vector<int> &nums, int target)
{
vector<int> dp(target + 1, 0);
dp[0] = 1;
for (int i = 1; i <= target; i++)
{
for (int j = 0; j < nums.size(); j++)
{
if (nums[j] <= i)
{
dp[i] += dp[i - nums[j]];
}
}
}
return dp[target];
}
};
int main()
{
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32