[15656] N과 M (7)

!·2022년 7월 16일
0

내 코드

#include <bits/stdc++.h>
using namespace std;

int arr[10];
int field[10];
int n,m;

void recursive(int k)
{
    if(k==m)
    {
        for(int i = 0;i<m;i++)
            cout << arr[i] << ' ';
        cout << '\n';
        return;
    }
    
    for(int i =0;i<n;i++)
    {
        arr[k] = field[i];
        recursive(k+1);
    }
}

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 0;i<n;i++)
        cin >> field[i];
    sort(field,field+n);
    recursive(0);
}
  • 정답코드도 이와 매우 유사하여 생략하겠습니다.
profile
개발자 지망생

0개의 댓글