[백준] 15649 N과 M (1)

0

백준

목록 보기
168/271
post-thumbnail

[백준] 15649 N과 M (1)

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

int n, m;
vector<bool> used;
vector<int> arr;

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

	for (int num = 1; num <= n; ++num) {
		if (used[num] == true) continue;

		used[num] = true;
		arr.push_back(num);

		makeArr();

		arr.pop_back();
		used[num] = false;
	}
}

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


	cin >> n >> m;

	for (int i = 0; i <= n; ++i) {
		used.push_back(false);
	}

	makeArr();

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

0개의 댓글