Cod sursa(job #1408579)
Utilizator | Data | 30 martie 2015 09:23:23 | |
---|---|---|---|
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[20],e;
bool a[20][20],v[20];
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;
}