Cod sursa(job #3326537)

Utilizator filipdanieloanFilip-Daniel Oancea filipdanieloan Data 29 noiembrie 2025 13:03:59
Problema Combinari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.93 kb
#include <bits/stdc++.h>
using namespace std;

int n, k;
array<int, 20> st;

bool validare_distincte(int nivel) {
    for(int i = 1; i < nivel; ++i) {
        if(st[i] == st[nivel]) {
            return false;
        }
    }
    return true;
}

bool check_increase(int nivel) {
    for(int i = 1; i < nivel; ++i) {
        if(st[i] > st[i+1]) {
            return false;
        }
    }
    return true;
}

void back(int nivel) {
    for(int i = 1; i <= n; ++i) {
        st[nivel] = i;
        if(validare_distincte(nivel) && check_increase(nivel)) {
            if(nivel == k) {
                for(int j = 1; j <= k; ++j) cout << st[j] << ' ';
                cout << '\n';
            } else back(nivel + 1);
        }
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
#ifndef LOCAL
    freopen("combinari.in", "r", stdin);
    freopen("combinari.out", "w", stdout);
#endif

    cin >> n >> k;
    back(1);

    return 0;
}