2 분 소요

🗒️ 15649번) N과 M (1)

#include <iostream>
using namespace std;

int N, M;
int arr[8];
int isused[8];

void GetSubSet(int count)
{
	if (count == M)
	{
		for (int i = 0; i < M; i++)
			cout << arr[i] << ' ';
		cout << '\n';
		return;
	}

	for (int i = 0; i < N; i++)
	{
		if (isused[i])
			continue;

		arr[count] = i+1;
		isused[i] = true;
		GetSubSet(count + 1);
		isused[i] = false;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> N >> M;
	GetSubSet(0);

	return 0;
}

카테고리:

업데이트:

댓글남기기