[백준] 📂. (15650번) N과 M (2)
🗒️ 15650번) N과 M (2)
#include <iostream>
using namespace std;
int sel[8];
bool isused[8];
int N, M;
void Sequence(int start, int count)
{
if (count == M)
{
for (int i = 0; i < M; i++)
cout << sel[i] << ' ';
cout << '\n';
return;
}
for (int i = start; i < N; i++)
{
if (isused[i])
continue;
sel[count] = i + 1;
isused[i] = true;
Sequence(i + 1, count + 1);
isused[i] = false;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M;
Sequence(0, 0);
return 0;
}
댓글남기기