반응형
//N과M(5)_15654.cpp - success
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool check[10];
int num[10];
void solve(int idx, vector <int>& buf, int n, int m) {
if (idx == m) {
for (int i = 0; i < m; i++) {
cout << num[i];
if (i != m - 1) cout << ' ';
}
cout << '\n';
return;
}
for (int i = 0; i < n; i++) {
if (check[i]) continue;
check[i] = true;
num[idx] = buf[i];
solve(idx + 1, buf, n, m);
check[i] = false;
}
}
int main() {
int n, m;
cin >> n >> m;
vector <int> buf(n);
for (int i = 0; i < n; i++) {
cin >> buf[i];
}
sort(buf.begin(), buf.end());
solve(0, buf, n, m);
return 0;
}
반응형
'개발(Dev) 이야기 > Algorithm' 카테고리의 다른 글
[BOJ] 리모컨_1107.cpp (0) | 2020.03.17 |
---|---|
[BOJ] N과M(6)_15655.cpp (0) | 2020.03.17 |
[BOJ] N과M(4)_15652.cpp (0) | 2020.03.17 |
[BOJ] N과M(3)_15651.cpp (0) | 2020.03.17 |
[BOJ] N과M(2)_15650.cpp (0) | 2020.03.17 |