#include <bits/stdc++.h>
using namespace std;
//14888 ㄱㄱ
int n,m;
int arr[10];
int num[10];
bool isused[10];
void NM(int now_n){
//기저
if(now_n==m) {
for(int i=0; i<m; i++) {
cout << arr[i] <<' ';
}
cout << '\n';
return;
}
for(int i=0; i<n; i++) {
if(!isused[i]) {
isused[i]=1;
arr[now_n]=num[i];
NM(now_n+1);
isused[i]=0;
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i=0; i<n; i++) {
cin >> num[i];
}
//정렬
sort(num,num+n);
NM(0);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: