Cod sursa(job #2093916)

Utilizator AkrielAkriel Akriel Data 24 decembrie 2017 16:50:33
Problema Submultimi Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include <bits/stdc++.h>

using namespace std;

int number,
    binaryPow;

ifstream fin("submultimi.in");

string binaryRepresentation;

template <class type>
void morphToGroup(type number, vector<int> &result){

    type bit = 1<<(int)(log2(number));
    for ( ;number or bit; bit>>=1 ){
        if ( number - bit >= 0 ){
            result.push_back(log2(bit)+1);
            number -= bit;
        }
    }
}

inline void solveProblem(){
    binaryPow = 1<<(number);

    for ( int index = 1; index < binaryPow; index++ ){
        vector <int> group;
        morphToGroup(index, group);

        vector <int> :: reverse_iterator element;
        for ( element = group.rbegin(); element < group.rend(); element++)
           printf("%d ", *element);
        printf("\n");
    }
}

int main(){
    fin >> number;
    freopen("submultimi.out", "w", stdout);
    solveProblem();
    return 0;
}