-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoPermutations.cpp
More file actions
49 lines (45 loc) · 978 Bytes
/
NoPermutations.cpp
File metadata and controls
49 lines (45 loc) · 978 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
46
47
48
49
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>>vec;
vector<vector<int>>Permutations(vector<int>v,int i=0)
{
if(i==v.size()-1)
vec.push_back(v);
else
{
for(int j=i;j<v.size();j++)
{
swap(v[i],v[j]);
Permutations(v,i+1);
swap(v[i],v[j]);
}
}
return vec;
}
vector<vector<int>> permute(vector<int>& nums) {
int i=0;
vector<vector<int>>res=Permutations(nums,i=0);
return res;
}
int main()
{
//cout<<"Hello World";
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int n;cin>>n;
vector<int>v;
for(int i=0;i<n;i++)
{
int a;cin>>a;
v.push_back(a);
}
vector<vector<int>>res=permute(v);
for(auto it:res)
{
for(int i:it)
{
cout<<i<<" ";
}
cout<<"\n";
}
}