Pagini recente » Cod sursa (job #3174536) | Cod sursa (job #3137360) | Cod sursa (job #456253) | Cod sursa (job #4459) | Cod sursa (job #2874658)
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 69
#define nl(...) 42
#endif
#define ll long long
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll random(ll st, ll dr) {
assert(st <= dr);
return st + rng() % (dr - st + 1);
}
const int MOD = 1e9 + 7;
const int N = 10;
ifstream in("permutari.in");
ofstream out("permutari.out");
int n;
int sol[N];
int lg[1 << N];
void back(int lvl, int mask) {
if (lvl == n) {
for (int i = 0; i < n; i++) {
out << sol[i] << ' ';
}
out << '\n';
return;
}
int cp = mask;
while (cp > 0) {
int id = lg[cp & -cp];
sol[lvl] = id + 1;
back(lvl + 1, mask ^ (1 << id));
cp -= cp & -cp;
}
}
void solve(int test, istream &cin, ostream &cout) {
in >> n;
for (int i = 0; i < n; i++) {
lg[1 << i] = i;
}
back(0, (1 << n) - 1);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
auto start = std::chrono::high_resolution_clock::now();
bool multiTest = false;
int t;
if (multiTest) {
cin >> t;
} else {
t = 1;
}
for (int test = 1; test <= t; test++) {
solve(test, cin, cout);
}
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
cerr << fixed << setprecision(6) << "Running time: " << (double) duration.count() / 1e6 << " seconds" << '\n';
return 0;
}