[BOJ] 15666번 : N과 M (12)
2024. 8. 18. 23:19ㆍAlgorithm
1. problem :
https://www.acmicpc.net/problem/15666
2. solution 1 :
#include <bits/stdc++.h>
using namespace std;
int N, M;
int nums[8];
int ans[8];
void backTrack(int k) {
if (k == M) {
for (int i = 0; i < M; i++) cout << nums[ans[i]] << ' ';
cout << '\n';
return;
}
int stt = 0;
if (k != 0) stt = ans[k - 1];
for (int i = stt; i < N; i++) {
ans[k] = i;
backTrack(k + 1);
}
}
vector<bool> chk(10002);
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
int idx = 0;
while (N--) {
cin >> nums[idx];
if (chk[nums[idx]]) continue;
chk[nums[idx]] = true;
idx++;
}
N = idx;
sort(nums, nums + N);
backTrack(0);
}
중복ele는 미리 제거함.
'Algorithm' 카테고리의 다른 글
| [BOJ] 1941번 : 소문난 칠공주 (0) | 2024.08.19 |
|---|---|
| [BOJ] 6603번 : 로또 (0) | 2024.08.19 |
| [BOJ] 15665번 : N과 M (11) (0) | 2024.08.18 |
| [BOJ] 15664번 : N과 M (10) (0) | 2024.08.18 |
| [BOJ] 15663번 : N과 M (9) (0) | 2024.08.18 |