Cod sursa(job #2174480)

Utilizator ade_tomiEnache Adelina ade_tomi Data 16 martie 2018 12:14:29
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include <iostream>
#include <fstream>

using namespace std;

const int NMAX = 20;

int st[NMAX], seen[NMAX], sol[NMAX], n, k;

ifstream fin("combinari.in");
ofstream fout("combinari.out");

void print_sol() {
    for (int i = 1; i <= k; i++) {
        fout << st[i] << ' ';
    }

    fout << '\n';
}

void back(int kp) {
    cout.flush();
    if (kp == k + 1) {
        print_sol();
        return;
    }

    for (int i = 1 + st[kp - 1]; i <= n; i++) {
        if (!seen[i]) {
            seen[i] = 1;
            st[kp] = i;
            
            back(kp + 1);

            seen[i] = 0;
        }
    }
}

int main() {

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

    return 0;
}