Cod sursa(job #3376588)

Utilizator RaduMoldovanMoldovan Radu RaduMoldovan Data 18 noiembrie 2026 14:19:19
Problema Submultimi Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
#include <bits/stdc++.h>
using namespace std;

int n;
vector<int> a;

bool urmator() {
    for (int i = n; i >= 1; i--) {
        if (a[i] == 0) {
            a[i] = 1;
            return true;
        }
        a[i] = 0; // Carry to the left
    }
    return false;
}

void afisare() {

    for (int i = 1; i <= n; i++) {
        if (a[i] == 1) {
            cout << i<<" ";
        }
    }
    cout << "\n";
}

int main() {
    cin >> n;
    a.resize(n + 1, 0); // Empty subset

    do {
        afisare();
    } while (urmator());
}