Cod sursa(job #1976473)

Utilizator MaligMamaliga cu smantana Malig Data 3 mai 2017 15:16:23
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
ifstream in("combinari.in");
ofstream out("combinari.out");

#define pb push_back
#define ll long long
const int NMax = 1e5 + 5;
const int inf = 1e9 + 5;

int N,K;
int v[NMax];

void backT(int);

int main() {
    in>>N>>K;

    backT(1);

    in.close();out.close();
    return 0;
}

void backT(int idx) {
    if (idx == K+1) {
        for (int i=1;i <= K;++i) {
            out<<v[i]<<' ';
        }
        out<<'\n';

        return;
    }

    int lim = N - (K - idx);
    for (int i = v[idx-1] + 1;i <= lim;++i) {
        v[idx] = i;
        backT(idx + 1);
    }
}