Cod sursa(job #2000372)
Utilizator | Andrei Feodorov Nashik | Data | 13 iulie 2017 14:53:57 |
---|---|---|---|
Problema | Problema Damelor | Scor | 90 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.89 kb |
//#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream cin("damesah.in");
ofstream cout("damesah.out");
int n,cnt;
bool ok=1;
struct queen
{
int r,c;
}v[20];
void func(int row)
{
if(row==n+1)
{
if(ok==1)
{
for(int i=1;i<=n;i++)
{
cout<<v[i].c<<" ";
}
cout<<endl;
}
cnt++;
ok=0;
}
for(int i=1;i<=n;i++)
{
bool k=1;
for(int j=1;j<row;j++)
{
if(i==v[j].c or abs(v[j].c-i)==abs(v[j].r-row))
{
k=0;
break;
}
}
if(k==1)
{
v[row].c=i;
v[row].r=row;
func(row+1);
}
}
}
int main()
{
cin>>n;
func(1);
cout<<cnt;
return 0;
}