Pagini recente » Cod sursa (job #666039) | Cod sursa (job #724841) | Cod sursa (job #1374872) | Cod sursa (job #63880) | Cod sursa (job #1402876)
#include<fstream>
#include<iostream>
using namespace std;
ifstream fin("damesah.in");
ofstream fout("damesah.out");
int n,s;
int a[15][15],v[15];
void citire()
{
fin>>n;
}
void afisare()
{
s++;
if(s==1){
for(int a1=1;a1<=n;a1++)
for(int a2=1;a2<=n;a2++)
{
if(a[a1][a2]==5) fout<<a2<<" ";
}
fout<<'\n';}
}
void back1(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)
{
a[x][a1]=5;
v[a1]=1;
x1=x+1;
y1=a1+1;
while(x1<=n and y1<=n)
{
a[x1][y1]=1;
x1++;
y1++;
}
x1=x+1;
y1=a1-1;
while(x1<=n and y1>=1)
{
a[x1][y1]=1;
x1++;
y1--;
}
back1(x);
x1=x;
y1=a1;
while(x1<=n and y1<=n)
{
a[x1][y1]=0;
x1++;
y1++;
}
x1=x;
y1=a1;
while(x1<=n and y1>=1)
{
a[x1][y1]=0;
x1++;
y1--;
}
v[a1]=0;
}
}
}
}
int main()
{
citire();
back1(0);
fout<<s;
}