Cod sursa(job #3297512)

Utilizator paulihno15Ciumandru Paul paulihno15 Data 22 mai 2025 18:55:02
Problema Combinari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.65 kb
#include <bits/stdc++.h>
#define NMAX 18

using namespace std;

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

int n, k;
int comb[NMAX + 2];

void afisare() {
    for (int i = 1; i <= k; i++) {
        fout << comb[i] << ' ';
    }
    fout << '\n';
}

void Back(int vf) {
    for (int i = comb[vf - 1] + 1; i <= n - k + vf; i++) {
        comb[vf] = i;
        if (vf == k) {
            afisare();
        }
        else {
            Back(vf + 1);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    fin.tie(NULL);
    fout.tie(NULL);

    fin >> n >> k;
    Back(1);
    return 0;
}