Pagini recente » Cod sursa (job #2872169) | Cod sursa (job #250216) | Cod sursa (job #2978551) | Cod sursa (job #2891226) | Cod sursa (job #2095955)
#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";
}
}