JXNVCE ALGO-LOG YouJin Jung

BOJ-15652

#include <iostream>

using namespace std;

int arr[9] = {0,};
bool visited[9] = {0,};

void dfs(int a, int b, int n, int m) {
    if (b == m) {
        for(int i = 0; i < m; i++)
            cout << arr[i] << ' ';
        cout << '\n';
        return;
    }
    for (int i = a; i <= n; i++) {
        visited[i] = true;
        arr[b] = i;
        dfs(i,b+1);
        visited[i] = false;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    dfs(1,0,n,m);
}