Cod sursa(job #2949805)

Utilizator DooMeDCristian Alexutan DooMeD Data 1 decembrie 2022 19:09:03
Problema Combinari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.54 kb
#include <bits/stdc++.h>
using namespace std;
const int nmax = 18;

ifstream f("combinari.in");
ofstream g("combinari.out");

int n, k, st[nmax+5];

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

void show() {
    for(int i=1; i<=k; i++) g << st[i] << " ";
    g << "\n";
}

void bt(int pos) {
    for(int i=1; i<=n; i++) {
        st[pos] = i;
        if(!ok(pos)) continue;

        if(pos == k) show();
        else bt(pos+1);
    }
}

int main() {
    f >> n >> k;
    bt(1);
    return 0;
}