-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
56 lines (48 loc) · 1.11 KB
/
test.cpp
File metadata and controls
56 lines (48 loc) · 1.11 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
#include <iostream>
#include <vector>
using namespace std;
int n = 5;
int r = 3;
bool visited1[101] = { false, };
bool visited2[101] = { false, };
void get_combinations(int idx, int depth) {
if(depth == r) {
for(int i=0; i<n; i++) {
if(visited1[i]) {
cout << i + 1 << " ";
}
}
cout << "\n";
}
for(int i=idx; i<n; i++) {
if(visited1[i] == false) {
visited1[i] = true;
get_combinations(i, depth + 1);
visited1[i] = false;
}
}
}
void get_permutations(vector<int> temp) {
if(temp.size() == r) {
for(int i=0; i<temp.size(); i++) {
cout << temp[i] << " ";
}
cout << "\n";
return;
}
for(int i=0; i<n; i++) {
if(visited2[i] == false) {
visited2[i] = true;
temp.push_back(i + 1);
get_permutations(temp);
temp.pop_back();
visited2[i] = false;
}
}
}
int main() {
get_combinations(0, 0);
cout << "----------\n";
vector<int> temp;
get_permutations(temp);
}