Cod sursa(job #1408577)

Utilizator teoceltareconstantin teodor teoceltare Data 30 martie 2015 09:20:44
Problema Problema Damelor Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 1.56 kb
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("damesah.in");
ofstream fout("damesah.out");
int n,nr[15],e;
bool a[15][15],v[15];
void afisare()
{
    e++;
    if(e==1)
    {
        for(int a1=1;a1<=n;a1++)
        {
            fout<<nr[a1]<<" ";
        }
        fout<<'\n';
    }
}
void fct(int x)
{
    int x1,y1;
    if(x==n)
    {
        afisare();
    }
    else
    {
        x++;
        for(int a1=1;a1<=n;a1++)
        {
            if(a[x][a1]==0 and v[a1]==0)
            {
                v[a1]=1;
                nr[x]=a1;
                x1=x;
                y1=a1;
                while(x1<n and y1<n)
                {
                    x1++;
                    y1++;
                    a[x1][y1]=1;
                }
                x1=x;
                y1=a1;
                while(x1<n and y1>1)
                {
                    x1++;
                    y1--;
                    a[x1][y1]=1;
                }
                fct(x);
                x1=x;
                y1=a1;
                while(x1<n and y1<n)
                {
                    x1++;
                    y1++;
                    a[x1][y1]=0;
                }
                x1=x;
                y1=a1;
                while(x1<n and y1>1)
                {
                    x1++;
                    y1--;
                    a[x1][y1]=0;
                }
                v[a1]=0;
            }
        }
    }
}
int main()
{
      fin>>n;
      fct(0);
      fout<<e;
}