Cod sursa(job #1011027)

Utilizator vlad.florescu94FMI Florescu Vlad - Adrian vlad.florescu94 Data 16 octombrie 2013 08:48:16
Problema Generare de permutari Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include <fstream>
#include <iostream>

using namespace std;
int st[9],n;

int valid (int k)
{
    int i=1;
    for (i=1;i<k;i++)
        if (st[i]==st[k]) return 0;
    return 1;
}

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

void bt (int k)
{
    for (st[k]=1;st[k]<n;st[k]++)
        if (valid(k))
            if (k==n) afis(n);
        else bt(k+1);
}

int main()
{
    cin>>n;
    bt(1);
    return 0;
}