Cod sursa(job #2325928)

Utilizator gabiluciuLuciu Gabriel gabiluciu Data 23 ianuarie 2019 11:01:03
Problema Generare de permutari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.09 kb
#include <cstdio>
#include <algorithm>
#include <time.h>
#include <queue>
#include <cmath>
#include <stack>
#include <fstream>
//#include <iostream>
#include <bitset>

using namespace std;
#define nl '\n'
#define all(v) v.begin(),v.end()
#define eb(x) emplace_back(x)
#define ull unsigned long long
#define N 1002
ifstream cin("permutari.in");
ofstream cout("permutari.out");

template<class a, class type>
void print(a v, type t) {
    for_each(all(v), [](type x) { cout << x << ' '; });
    cout << nl;
}

double logXBaseY(double X, double Y) {
    return log2(X) / log2(Y);
}

int ver[20], n;
vector<int> ans;

inline void bkt() {
    for (int i = 1; i <= n; ++i) {
        if (!ver[i]) {
            ver[i] = 1;
            ans.eb(i);
            if (ans.size() == n) {
                print(ans, (int) 0);
            } else
                bkt();
            ans.pop_back();
            ver[i] = 0;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    clock_t tStart = clock();
    cin >> n;
    bkt();
    //    printf("\nTime taken: %.2fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
}