Pagini recente » Cod sursa (job #1369037) | Cod sursa (job #898425) | Cod sursa (job #348459) | Cod sursa (job #2105582) | Cod sursa (job #1104719)
#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std;
int st[20],n,k,p,c=0;
bool as,ev,stop,ok=true;
void succ(bool &as)
{
if (st[k]<n)
{
st[k]=st[k]+1;
as=true;
}
else as=false;
}
void valid(bool &ev)
{
int i,nr,nr2;
ev=1;
for(i=1;i<=k-1;++i)
{
nr=st[k]-st[i];if (nr<0) nr=nr*(-1);
nr2=k-i;if (nr2<0) nr2=nr2*(-1);
if (nr==nr2 || st[k]==st[i]) {ev=false;break;}
}
}
void tipareste()
{
int i;
for(i=1;i<=k;++i) printf("%d ",st[i]);printf("\n");
}
int main()
{
freopen("damesah.in","r",stdin);
scanf("%d",&n);
freopen("damesah.out","w",stdout);
k=1;
st[1]=0;
while(k>0)
{
stop=false;
do
{
succ(as);
if (as) valid(ev);
if (!as || (as && ev)) stop=true;
}
while(!stop);
if (as)
{
if (k==n) {if (ok) tipareste();ok=false;++c;}
else {++k;st[k]=0;}
}
else --k;
}
printf("%d",c);
return 0;
}