Cod sursa(job #1335520)

Utilizator GinguIonutGinguIonut GinguIonut Data 5 februarie 2015 17:25:15
Problema Problema Damelor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include <fstream>
#include <math.h>
using namespace std;
ifstream fin("damesah.in");
ofstream fout("damesah.out");
int v[14],nr,cond1,cond2,k,i,n;
int main()
{
    fin>>n;
    k=1;
    v[k]=0;
    while(k>0)
    {
        do
        {
            if(v[k]<n)
            {
                v[k]++;
                cond1=cond2=1;
                for(i=1;i<k;i++)
                {
                    if(v[i]==v[k]||v[i]-v[k]==k-i||v[k]-v[i]==k-i)
                        cond1=0;
                }
            }
            else
                cond2=0;
        }
        while(!cond1&&cond2);
            if(cond2)
                if(k==n)
                    nr++;
                else
                    v[++k]=0;
            else
                k--;
    }
    fout<<nr;
    return 0;
}