Cod sursa(job #2023424)

Utilizator VarticeanNicolae Varticean Varticean Data 18 septembrie 2017 22:08:06
Problema Problema Damelor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.51 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("damesah.in");
ofstream out("damesah.out");
int c[14], d1[14], d2[14];
int cnt,n ;
void solve( int y )
{
    if ( y == n )
    {
        cnt ++;
        return;
    }

    for (int x=0; x<n; x++)
    {
        if( c[x] || d1[x+y] || d2[x-y+n+1] ) continue;
        c[x] = d1[x+y] = d2[x-y+n+1]=1;
        solve(y+1);
        c[x] = d1[x+y] = d2[x-y+n+1]=0;
    }
}
int main()
{
    in >> n;
    solve(0);
    out << cnt;

    return 0;
}