Cod sursa(job #1867709)

Utilizator preda.andreiPreda Andrei preda.andrei Data 4 februarie 2017 11:50:05
Problema Submultimi Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <fstream>
#include <vector>

using namespace std;

void PrintVector(const vector<int> &vec, int n, ofstream &f)
{
    for (int i = 0; i < n; ++i) {
        f << vec[i] << " ";
    }
    f << "\n";
}

void Back(unsigned lev, vector<int> &st, ofstream &f)
{
    for (unsigned i = (lev == 0) ? 0 : st[lev - 1]; i < st.size(); ++i) {
        st[lev] = i + 1;
        PrintVector(st, lev + 1, f);
        if (lev + 1 < st.size()) {
            Back(lev + 1, st, f);
        }
    }
}

void Sub(int n, ofstream &f)
{
    vector<int> st(n, 0);
    Back(0, st, f);
}

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

    int n;
    fin >> n;

    Sub(n, fout);
    return 0;
}