Cod sursa(job #2025277)

Utilizator SlevySlevoaca Stefan-Gabriel Slevy Data 22 septembrie 2017 12:33:27
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.87 kb
#include <iostream>
#include <fstream>
#define NMAX 19

using namespace std;

using _int = short int;
_int _stack[NMAX], vf;

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

inline bool ok() {

    if (vf > 1)
    {
        if (_stack[vf] <= _stack[vf - 1])
            return false;
    }
    return true;
}

inline void print() {

    for (_int i = 1; i <= vf; i++)
        out << _stack[i] << " ";
    out << "\n";
}

int main() {

    _int N, k;
    in >> N >> k;
    in.close();

    _stack[++vf] = 0;

    while (vf) {

        _stack[vf]++;
        if (_stack[vf] > N)
            vf--;
        else {

            if (ok()) {

                if (vf == k)
                    print();
                else
                    _stack[++vf] = 0;
            }
        }
    }

    out.close();
    return 0;
}