Cod sursa(job #3355189)

Utilizator Razvan25555Razvan Razvan25555 Data 21 mai 2026 23:37:51
Problema Submultimi Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
// Ionascu George-Razvan, 324CA

#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

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

vector<int> a, visited;

void bkt(int n, int poz) {
    if ((int) a.size() <= n && (int) a.size() != 0) {
        for (int i = 0; i < (int) a.size(); i++) {
            fout << a[i] << " ";
        }
        fout << "\n";
    }

    for (int i = poz; i <= n; i++) {
        if (visited[i] == 0) {
            visited[i] = 1;
            a.push_back(i);

            bkt(n, i);

            a.pop_back();
            visited[i] = 0;
        }
    }
}

int main() {
    int n;
    fin >> n;

    visited.resize(n + 1, 0);

    bkt(n, 1);
    
    fin.close();
    fout.close();
    return 0;
}