Cod sursa(job #1819948)

Utilizator GeoeyMexicanuBadita George GeoeyMexicanu Data 30 noiembrie 2016 23:51:41
Problema Generare de permutari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("permutari.in");
ofstream g("permutari.out");
int i,j,n,v[25];
void tipar()
{
    int i;
    for(i=1;i<=n;i++)
        g<<v[i]<<' ';
    g<<'\n';
}
void bktr(int val,int p)
{
    v[p]=val;
    if(p==n)
        tipar();
    else
    {
        for(int t=1;t<=n;t++)
        {
            int ok=1;
            for(int j=1;j<=p;j++)
                if(v[j]==t)
                ok=0;
            if(ok==1)
                bktr(t,p+1);
        }
    }
}
int main()
{
    f>>n;
    bktr(0,0);
}