Cod sursa(job #2900960)

Utilizator toma_ariciuAriciu Toma toma_ariciu Data 12 mai 2022 17:01:41
Problema Generare de permutari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
#include <fstream>

using namespace std;

ifstream fin("permutari.in");
ofstream fout("permutari.out");

int n, sol[10];
bool used[10];

void bkt(int k)
{
    for(int i = 1; i <= n; i++)
    {
        if(used[i])
            continue;
        sol[k] = i;
        used[i] = 1;
        if(k == n)
        {
            for(int j = 1; j <= n; j++)
                fout << sol[j] << ' ';
            fout << '\n';
        }
        else
            bkt(k + 1);
        used[i] = 0;
    }
}

int main()
{
    fin >> n;
    bkt(1);
    return 0;
}