-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathmain.cpp
More file actions
45 lines (42 loc) · 880 Bytes
/
main.cpp
File metadata and controls
45 lines (42 loc) · 880 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
void solve(int index, vector<vector<int>> output, vector<int> arr)
{
if (index == arr.size())
{
output.push_back(arr);
return;
}
for (int i = index; i < arr.size(); i++)
{
int temp = arr[index];
arr[index] = arr[i];
arr[i] = temp;
solve(index + 1, output, arr);
temp = arr[index];
arr[index] = arr[i];
arr[i] = temp;
}
}
int main()
{
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
vector<vector<int>> output;
solve(0, output, arr);
for (int i = 0; i < output.size(); i++)
{
for (int j = 0; j < output[i].size(); j++)
{
cout << output[i][j] << " ";
}
cout << endl;
}
return 0;
}