#include <iostream>
#include <algorithm>
using namespace std;
int arr[8];
int selIdx[8];
int N, M;
void Sequence(int count)
{
if (count == M)
{
for (int i = 0; i < M; i++)
cout << arr[selIdx[i]] << ' ';
cout << '\n';
return;
}
int start = max(0, count - 1);
for (int i = selIdx[start]; i < N; i++)
{
selIdx[count] = i;
Sequence(count + 1);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M;
for (int i = 0; i < N; i++)
cin >> arr[i];
sort(arr, arr + N);
Sequence(0);
return 0;
}
댓글남기기