티스토리 뷰
https://www.acmicpc.net/problem/15655
[백준][C++] 15655 N과 M (6)
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
void dfs(int n, int N, int M, vector<int> vec, vector<int> out, vector<int> visit) {
if (out.size() == M) {
for (int i : out) {
cout << i << ' ';
}
cout << '\n';
return;
}
for (int i = n; i < N; i++) {
out.push_back(vec[i]);
dfs(i + 1, N, M, vec, out, visit);
out.pop_back();
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, M;
cin >> N >> M;
vector<int> vec(N, 0);
for (int i = 0; i < N; i++) {
cin >> vec[i];
}
sort(vec.begin(), vec.end());
vector<int> out;
vector<int> visit(N, 0);
dfs(0, N, M, vec, out, visit);
return 0;
}
'Problem Solving' 카테고리의 다른 글
[프로그래머스][C++] 영어 끝말잇기 (0) | 2022.06.03 |
---|---|
[프로그래머스][C++] 예상 대진표 (0) | 2022.05.31 |
[백준][C++] 15654 N과 M (5) (0) | 2022.05.27 |
[프로그래머스][C++] 소수 찾기 (0) | 2022.05.26 |
[백준][C++] 15652 N과 M (4) (0) | 2022.05.26 |
댓글