-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubsets.cpp
More file actions
57 lines (52 loc) · 1.15 KB
/
Copy pathSubsets.cpp
File metadata and controls
57 lines (52 loc) · 1.15 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
void Combination(vector<vector<int>> &result, int element);
vector<vector<int>> Subsets(vector<int> &S)
{
sort(S.begin(),S.end());
vector<vector<int>> result;
vector<int> temp;
temp.push_back(S[0]);
result.push_back(temp);
for (int i = 1; i < S.size(); i++)
{
Combination(result, S[i]);
}
vector<int> emp;
result.push_back(emp);
return result;
}
void Combination(vector<vector<int>> &result, int element)
{
int result_size = result.size();
for (int i = 0; i < result_size; i++)
{
vector<int> temp = result[i];
temp.push_back(element);
result.push_back(temp);
}
vector<int> current_element;
current_element.push_back(element);
result.push_back(current_element);
}
int main()
{
vector<int> v;
v.push_back(2);
v.push_back(1);
v.push_back(3);
vector<vector<int>> test;
test = Subsets(v);
cout << test[0][0] << endl;
cout << test[1][0] << endl;
cout << test[1][1] << endl;
cout << test[2][0] << endl;
cout << test[3][0] << endl;
cout << test[4][0] << endl;
cout << test[5][0] << endl;
cout << test[6][0] << endl;
//cout << test[7][0] << endl;
return 0;
}