Pagini recente » Cod sursa (job #2579983) | Cod sursa (job #3041259) | Cod sursa (job #1431064) | Cod sursa (job #1617507) | Cod sursa (job #1424528)
#include <fstream>
#include <cstdlib>
using namespace std;
/*ifstream cin("Dame.in");
ofstream cout("Dame.out");*/
ifstream cin("damesah.in");
ofstream cout("damesah.out");
int n,v[20],nr,mij;
void Tipar()
{
for(int j=1;j<=n;++j)
cout<<v[j]<<" ";
cout<<'\n';
}
int Valid(int i)
{
int dif=0;
for(int j=1;j<i;++j)
{
if(v[i]==v[j])
return 0;
dif=i-j;
if(v[i]==v[j]-dif||v[i]==v[j]+dif)
return 0;
}
return 1;
}
void Back(int i)
{
if(v[1]>mij)
{
nr*=2;
cout<<nr;
exit(0);
}
else
{
if(i>n)
{
if(nr==0)
Tipar();
nr++;
}
else
for(int j=1;j<=n;++j)
{
v[i]=j;
if(Valid(i))
Back(i+1);
}
}
}
int main()
{
cin>>n;
mij=n/2;
if(n%2==1)
++mij;
Back(1);
cout<<nr;
return 0;
}