Recent Posts
Notice
No Rules Rules
N과 M (4) (feat. 백준, 15652번) 본문
728x90
반응형
N과 M (4)
https://www.acmicpc.net/problem/15652
15652번: N과 M (4)
한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다. 수열은 사전 순으로 증가하는 순서로 출력해
www.acmicpc.net
반응형
// woohyeon.kim
// https://www.acmicpc.net/problem/15652
#include <iostream>
#include <algorithm>
using namespace std;
int N, M, arr[9];
void dfs(register int index, register int count) {
if (count == M) {
for (register int i = 1; i <= M; ++i)
cout << arr[i] << " ";
cout << "\n";
return;
}
for (register int i = index; i <= N; ++i) {
arr[count + 1] = i;
dfs(i, count + 1);
arr[count + 1] = 0;
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(NULL);
fill(arr, arr + 9, 0);
cin >> N >> M;
dfs(1, 0);
return 0;
}
// *&)*@*
중복조합을 구하는 문제입니다.
728x90
반응형
'생활 > 코테' 카테고리의 다른 글
스도쿠 (feat. 백준, 2580번) (0) | 2022.08.05 |
---|---|
N-Queen (feat. 백준, 9663번) (0) | 2022.08.05 |
N과 M (3) (feat. 백준, 15651번) (0) | 2022.08.05 |
N과 M (2) (feat. 백준, 15650번) (0) | 2022.08.05 |
N과 M (1) (feat. 백준, 15649번) (0) | 2022.08.05 |
Comments