Cod sursa(job #1914841)

Utilizator zeboftwAlex Mocanu zeboftw Data 8 martie 2017 18:42:59
Problema Submultimi Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include <fstream>

using namespace std;

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

int n, stiva[17];

void bkt (int);
bool corect (int);

int main()
{
    fin >> n;
    bkt(1);
    return 0;
}

void bkt (int level) {
    for (int i=level; i<=n; i++) {
        stiva[level] = i;
        if (corect(level)) {
            for (int j=1; j<=level; j++) fout << stiva[j] << ' ';
            fout << '\n';
            if (level < n) bkt(level+1);
        }
    }
}

bool corect(int level) {
    for (int i=1; i < level; i++) if (stiva[i] >= stiva[level]) return 0;
    return 1;
}