Pagini recente » Cod sursa (job #5205) | Cod sursa (job #1785513) | Cod sursa (job #2233558) | Cod sursa (job #1916563) | Cod sursa (job #2322848)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("damesah.in");
ofstream g("damesah.out");
int n,d,tot,stk[14];
bool ok;
bool verif(int i,int k)
{
for(d=1; d<k; ++d)
if(abs(i-stk[d])==k-d || i==stk[d])
return 0;
return 1;
}
void btk(int k)
{
if(k>n)
{
++tot;
if(!ok)
{
for(d=1; d<=n; ++d)
g<<stk[d]<<' ';
ok=1;
}
}
else
for(int i=1; i<=n; ++i)
if(verif(i,k))
stk[k]=i,btk(k+1);
}
int main()
{
f>>n;
btk(1);
g<<'\n'<<tot;
}