forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0377.cpp
More file actions
30 lines (28 loc) · 649 Bytes
/
0377.cpp
File metadata and controls
30 lines (28 loc) · 649 Bytes
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
#include <iostream>
#include <vector>
using namespace std;
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
int combinationSum4(vector<int>& nums, int target)
{
vector<int> mem(target + 1, 0);
mem[0] = 1;
for(int i = 1; i <= mem.size(); i++)
{
for (auto& num : nums)
{
if (i >= num) mem[i] += mem[i - num];
}
}
return *mem.rbegin();
}
};
int main()
{
vector<int> nums = {1, 2, 4};
int target = 32;
cout << Solution().combinationSum4(nums, target);
return 0;
}