Cod sursa(job #2095955)

Utilizator epermesterNagy Edward epermester Data 28 decembrie 2017 13:45:36
Problema Submultimi Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include<fstream>
#include<cmath>
using namespace std;

const int MAX_COUNT = 35536;

int main() {
	ifstream in("submultimi.in");
	ofstream out("submultimi.out");
	short n;
	in >> n;
	int* count = new int[n];
	int* max = new int[n];
	for (int i = 1;i < n;++i) {
		max[i] = pow(2, n - i - 1);
		count[i] = MAX_COUNT + 1;
	}
	max[0] = pow(2, n - 1);
	count[0] = 0;
	int max_rows = pow(2, n)-1;
	for (;max_rows;max_rows--)				//
	{
		for (short i = 0;i < n;++i) {
			if (count[i] == max[i]) {
				count[i]++;
				count[i + 1] = 0;
			}
			if (count[i] < max[i]) {
				out << i + 1 << " ";
				count[i]++;
				if (count[i] == 2 && i + 1 < n) {
					count[i + 1] = 0;
				}
			}
		}
		out << "\n";
	}
}