Cod sursa(job #1934722)

Utilizator WebDesignbyTMGhiorghiu Ioan-Viorel WebDesignbyTM Data 21 martie 2017 19:09:17
Problema Generare de permutari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
#include <fstream>
#include <bitset>
#define DM 9
using namespace std;

ifstream fi ("permutari.in");
ofstream fo ("permutari.out");
bitset <DM> bs;
int v[DM], n, pos;

void bkt(int pos)
{
    if (pos == n + 1)
    {
        for (int i = 1; i < pos; ++i)
            fo << v[i] << ' ';
        fo << '\n';
    }
    else
    for (int i = 1; i <= n; ++i)
        if (bs[i] == 0)
        {
            v[pos] = i;
            bs[i] = 1;
            bkt(pos + 1);
            bs[i] = 0;
        }
}

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