[C++] 15650: N과 M (4)

우나·2022년 11월 10일

백준

목록 보기
11/16

정답코드

#include <iostream>
using namespace std;

#define MAX 9

int arr[MAX];
bool visit[MAX] = { false };
int N{ 0 }, M{ 0 };

void NandM(int depth) {
	if (depth == M) {
		for (int i = 0; i < depth; i++) cout << arr[i] << " ";
		cout << "\n";
	}
	else {
		for (int i = 1; i <= N; i++) {
			if (arr[depth - 1] <= i) {
				arr[depth] = i;
				NandM(depth + 1);
			}
		}
	}
}
int main() {
	cin >> N >> M;
	NandM(0);
}



0개의 댓글