[백준] 15652 N과 M (4)

0

백준

목록 보기
179/271
post-thumbnail

[백준] 15652 N과 M (4)

#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

int n, m;
vector<int> arr;

void makeArr() {
	//base case
	if (arr.size() == m) {
		for (int i = 0; i < m; ++i) {
			cout << arr[i] << " ";
		}
		cout << "\n";
		return;
	}

	if (arr.empty()) {
		for (int num = 1; num <= n; ++num) {
			arr.push_back(num);
			makeArr();
			arr.pop_back();
		}
	}
	else {
		for (int num = arr.back(); num <= n; ++num) {
			arr.push_back(num);
			makeArr();
			arr.pop_back();
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	cin >> n >> m;

	makeArr();

	return 0;
}
profile
Be able to be vulnerable, in search of truth

0개의 댓글