-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path491.cpp
31 lines (28 loc) · 888 Bytes
/
491.cpp
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
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
/**
* dfs + set去重复
*
*/
vector<vector<int>> findSubsequences(vector<int>& nums) {
// unordered_map<int, vector<int>> cache; /*第一个是int(pos), 第二个是vector<int>, 存的缓存的结果*/
vector<int> pre;
set<vector<int>> res;
dfs(nums, 0, pre, -101, res);
return vector<vector<int>>(res.begin(), res.end());
}
void dfs(vector<int>& nums, int pos, vector<int> pre, int pre_value, set<vector<int>> &res) {
int n = nums.size();
if (pre.size()>1)
res.insert(pre);
for (int i = pos; i < n; ++i) {
if (nums[i] >= pre_value) {
pre.push_back(nums[i]);
dfs(nums, i+1, pre, nums[i], res);
pre.pop_back(); // 吐出去
}
}
}
};