#include <bits/stdc++.h>
using namespace std;
//14888 ㄱㄱ
int n,m;
int arr[10];
int num[10];
int is_used[10];

void NM(int now_n){
    if(now_n==m) {
        for(int i=0; i<m; i++) cout << arr[i];
        return;
    }
    int tmp=0;
    for(int i=0; i<n; i++) {
        //사용 안됨 + 이전 단계 수열의 끝이랑 다름 
        if(!is_used[i] && tmp!=num[i]) {
            is_used[i]=1;
            arr[now_n]=num[i];
            tmp=arr[now_n];
            NM(now_n+1);
            is_used[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;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: