-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSA01006.cpp
More file actions
43 lines (41 loc) · 692 Bytes
/
Copy pathDSA01006.cpp
File metadata and controls
43 lines (41 loc) · 692 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
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
long long sum = 1;
int a[n];
int x = 0;
for(int i = 1; i<=n; i++)
{
sum*=i;
a[x++] = i;
}
vector <int> v;
while(sum--)
{
for(int i = n-1; i>-1; i--)
{
v.push_back(a[i]);
}
next_permutation(a, a+n);
}
int check = n;
for(int i = v.size()-1; i>-1; i--)
{
cout << v[i];
check--;
if(!check)
{
cout << ' ';
check = n;
}
}
cout << endl;
}
}