Cod sursa(job #2817044)

Utilizator hoprixVlad Opris hoprix Data 12 decembrie 2021 18:51:23
Problema Submultimi Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.58 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;

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

int n, cnt;
bool u[17];

void bk(int k) {
    if (k == n+1) {
        cnt++;
        if (cnt == 1)
            return;
        for (int j = 1; j <= k; j++)
            if (u[j]) fout << j << " ";
        fout << "\n";
    }
    else {
        bk(k+1);
        u[k] = 1;
        bk(k+1);
        u[k] = 0;
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    fin >> n; 
    bk(1);

    return 0;
}