Pagini recente » Cod sursa (job #56422) | Cod sursa (job #3253148) | Cod sursa (job #2378014) | Cod sursa (job #2273554) | Cod sursa (job #1335523)
#include <fstream>
#include <math.h>
using namespace std;
ifstream fin("damesah.in");
ofstream fout("damesah.out");
int v[14],nr,cond1,cond2,k,i,n,ok;
int main()
{
fin>>n;
k=1;
v[k]=0;
while(k>0)
{
do
{
if(v[k]<n)
{
v[k]++;
cond1=cond2=1;
for(i=1;i<k;i++)
{
if(v[i]==v[k]||v[i]-v[k]==k-i||v[k]-v[i]==k-i)
cond1=0;
}
}
else
cond2=0;
}
while(!cond1&&cond2);
if(cond2)
if(k==n)
{
nr++;
if(ok==0)
{
ok=1;
for(i=1;i<=n;i++)
fout<<v[i]<<" ";
fout<<'\n';
}
}
else
v[++k]=0;
else
k--;
}
fout<<nr;
return 0;
}