Pagini recente » Autentificare | Cod sursa (job #7042) | Cod sursa (job #2977591) | Cod sursa (job #462906) | Cod sursa (job #2322837)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("damesah.in");
ofstream g("damesah.out");
int n,d,tot,stk[14];
bool ok,da;
void afs()
{
for(int i=1; i<=n; ++i)
g<<stk[i]<<' ';
}
void btk(int k)
{
if(k>n)
{
tot++;
if(!ok)
{
afs();
ok=1;
}
}
else
{
for(int i=1; i<=n; ++i)
{
da=1;
for(d=1; d<k; ++d)
if(abs(i-stk[d])==k-d || i==stk[d])
{
da=0;
break;
}
if(da)
stk[k]=i,btk(k+1);
}
}
}
int main()
{
f>>n;
btk(1);
g<<'\n'<<tot;
}