알고리즘 문제
[백준] 10974번 모든 순열
feelcoding
2021. 1. 5. 13:15
728x90
#include <iostream>
#include <vector>
using namespace std;
int n;
void permutation(int num, vector<bool> visited, vector<int> result) {
if (num == n) {
for (int i = 0; i < n; i++) {
cout << result[i] << " ";
}
cout << '\n';
return;
}
for (int i = 0; i < n; i++) {
if (!visited[i]) {
result[num] = i + 1;
visited[i] = true;
permutation(num + 1, visited, result);
visited[i] = false;
}
}
}
int main() {
cin.tie(NULL);
ios::sync_with_stdio(false);
cin >> n;
permutation(0, vector<bool>(n, false), vector<int>(n));
return 0;
}
728x90