[C++] BAEKJOON 15652

HYOoMi·2021년 3월 16일
0

N과 M(4)

코드

#include <iostream>
#define MAX 9
using namespace std;

int N, M;
int arr[MAX];

void dfs(int first, int cnt) {
	if (cnt == M) {
		for (int i = 0; i < M; i++) {
			cout << arr[i] << ' ';
		}
		cout << '\n';
		return;
	}
	for (int i = first; i <= N; i++){
		arr[cnt] = i;
		dfs(i, cnt + 1);
	}
}

int main(void) {
	cin.tie(NULL);  ios::sync_with_stdio(false);
	cin >> N >> M;
	dfs(1, 0);
}

0개의 댓글

관련 채용 정보