Cod sursa(job #3284450)

Utilizator mateistefan11matei stefan mateistefan11 Data 11 martie 2025 17:26:39
Problema Generare de permutari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int n;
bitset<10001> fr;
int st[1005];
void Afis(int n)
{
    for(int i = 1; i <= n; i++)
        fout << st[i] << " ";
    fout << "\n";
}
void Back(int top)
{
    if(top == n + 1)
        Afis(n);
    else for(int i = 1; i <= n; i++)
        if(fr[i] == 0)
        {
            fr[i] = 1;
            st[top] = i;
            Back(top + 1);
            fr[i] = 0;
        }
}
int main()
{
    ios_base::sync_with_stdio(0);
    fin.tie(0);
    fout.tie(0);
    int i,j;
    fin >> n;
    Back(1);
    return 0;
}