Cod sursa(job #1809923)

Utilizator DEIK_CUNBM_TEAMNorthrendland DEIK_CUNBM_TEAM Data 19 noiembrie 2016 13:43:00
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#include <bits/stdc++.h>
using namespace std;
const char* IN = "combinari.in";
const char* OUT = "combinari.out";
const int Nmax = 20;

namespace InputStream {
    FILE *in = fopen(IN,"r");
    int nextInt(){
        int aux;
        fscanf(in,"%d",&aux);
        return aux;
    }
}

namespace PrintStream {
    FILE *out = fopen(OUT,"w");
    void printInt(int nbr){
        fprintf(out,"%d ",nbr);
    }
    void endline(){
        fprintf(out,"\n");
    }
}

namespace Math {
    vector <int> st(0);
    void generateComb(int n,int k,int step){
        if (step>=k) {
            for_each(st.begin(),st.end(),PrintStream::printInt);
            PrintStream::endline();
            return;
        }
        for (int i=1;i<=n;++i){
            if (step == 0 || i>st[step-1]) {
                st.push_back(i);
                generateComb(n,k,step+1);
                st.pop_back();
            }
        }
    }
}

int main(void){
    int n = InputStream::nextInt();
    int k = InputStream::nextInt();
    Math::generateComb(n,k,0);
    return 0;
}