Cod sursa(job #2292312)

Utilizator ALEx6430Alecs Andru ALEx6430 Data 29 noiembrie 2018 12:55:14
Problema Problema Damelor Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.78 kb
#include <bits/stdc++.h>
using namespace std;

ifstream in("damesah.in");
ofstream out("damesah.out");

short n, x[15], l[15], d1[15], d2[15], sol;

void bkt(int k)
{
    if(k-1 == n)
    {
        if(++sol == 1)
        {
            for(int i = 1; i <= n; i++) out << x[i] << ' ';
            out << '\n';
        }
    }
    else
    {
        for(int i = 1; i <= n; i++)
            if(!l[i] && !d1[i-k+n] && !d2[i+k])
            {
                l[i] = 1; d1[i-k+n] = 1; d2[i+k] = 1;
                x[k] = i;

                bkt(k+1);

                l[i] = 0; d1[i-k+n] = 0; d2[i+k] = 0;
            }
    }
}

int main()
{
//    ios_base::sync_with_stdio(0);
//    in.tie(0);

    in >> n;

    bkt(1);

    out << sol;

    return 0;
}