-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy path10974.cpp
More file actions
28 lines (28 loc) · 708 Bytes
/
10974.cpp
File metadata and controls
28 lines (28 loc) · 708 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
#include <string>
#include <iostream>
#include <stdio.h>
using namespace std;
int N;
void print_permutation(string prefix, int* isused, int left) {
if (left == 1) {
for (int i = 1; i <= N; i++) {
if (!isused[i]) {
cout << prefix + to_string(i) + " " + "\n";
return;
}
}
}
for (int i = 1; i <= N; i++) {
if (!isused[i]) {
isused[i] = true;
print_permutation(prefix + to_string(i) + " ", isused, left - 1);
isused[i] = false;
}
}
}
int main(void) {
scanf("%d", &N);
int isused[9] = { false, };
string prefix = "";
print_permutation(prefix, isused, N);
}