💻 C++ 기반
#include <cstdio>
#define MAX 9
using namespace std;
int N, M;
int arr[MAX];
bool isUsed[MAX];
void func(int K)
{
if (K == M)
{
for (int i = 0; i < M; i++)
{
printf("%d ", arr[i]);
}
printf("\n");
return;
}
for (int i = 1; i <= N; i++)
{
if (!isUsed[i])
{
if (K == 0 || K != 0 && arr[K - 1] < i)
{
isUsed[i] = true;
arr[K] = i;
func(K + 1);
isUsed[i] = false;
}
}
}
}
int main()
{
scanf("%d %d", &N, &M);
func(0);
return 0;
}
#include <cstdio>
#include <algorithm>
#define MAX 9
using namespace std;
int N, M;
int arr[MAX];
int main()
{
scanf("%d %d", &N, &M);
for (int i = 0; i < M; i++)
{
arr[i] = 0;
}
for (int i = M; i < N; i++)
{
arr[i] = 1;
}
do
{
for (int i = 0; i < N; i++)
{
if (!arr[i])
{
printf("%d ", i + 1);
}
}
printf("\n");
} while (next_permutation(arr, arr + N));
return 0;
}