-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathL491.cpp
41 lines (41 loc) · 872 Bytes
/
L491.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
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
class Solution{
public:
vector<vector<int>> res;
vector<int> path;
void dfs(vector<int>& nums, int startindex){
if (path.size() >= 2)
res.push_back(path);
unordered_set<int> myset;
for (int i = startindex; i < nums.size(); i++){
if ((!path.empty() && nums[i] < path.back()) || myset.find(nums[i]) != myset.end())
continue;
myset.insert(nums[i]);
path.push_back(nums[i]);
dfs(nums, i + 1);
path.pop_back();
}
}
vector<vector<int>> findSubsequences(vector<int>& nums){
dfs(nums, 0);
return res;
}
};
int main(){
int tmp;
Solution sol;
vector<int> nums;
while(cin >> tmp)
nums.push_back(tmp);
sol.findSubsequences(nums);
for (auto &x : sol.res){
for (auto y : x){
cout << y << " ";
}
cout << "\n";
}
return 0;
}