Pagini recente » Cod sursa (job #108349) | Cod sursa (job #1283093) | Cod sursa (job #497195) | Cod sursa (job #1666047) | Cod sursa (job #2095959)
#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]++;
if (i + 1 < n)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";
}
}