Cod sursa(job #1916733)

Utilizator andrei1299Ghiorghe Andrei Alexandru andrei1299 Data 9 martie 2017 10:14:44
Problema Generare de permutari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.59 kb
#include <bits/stdc++.h>

using namespace std;
int n,st[10];
bool viz[10];
ofstream fout("permutari.out");

void Afisare()
{
    for(int i=1;i<=n;i++)
        fout<<st[i]<<" ";
    fout<<"\n";
}

void Backt(int top)
{
    if(top==n+1) Afisare();
    else
    {
        for(int i=1;i<=n;i++)
            if(viz[i]==0)
        {
            viz[i]=1;
            st[top]=i;
            Backt(top+1);
            viz[i]=0;
        }
    }
}

int main()
{
    ifstream fin("permutari.in");
    fin>>n;
    fin.close();
    Backt(1);
    fout.close();
    return 0;
}