Cod sursa(job #1926753)

Utilizator teodorgTeodor G teodorg Data 14 martie 2017 17:40:37
Problema Problema Damelor Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("damesah.in");
ofstream g("damesah.out");
int sol[14]={0,0,0,0,2,10,4,40,92,352,724,2680,14200,73712},n,a[30],b[30],c[30],d[30];
void linia(int );
int main()
{
    f>>n;
    linia(1);
    return 0;
}
void linia(int L)
{
    int C;
    if(L==n+1)
    {
            for(C=1;C<=n;C++)
                g<<d[C]<<' ';
            g<<'\n'<<sol[n];
            exit(0);
    }
    for(C=1;C<=n;C++)
    {
        if(a[C])continue;
        if(b[n+C-L])continue;
        if(c[C+L-1])continue;
        a[C]=b[n+C-L]=c[C+L-1]=1;d[L]=C;
        linia(L+1);
        a[C]=b[n+C-L]=c[C+L-1]=0;

    }

}