Pagini recente » Cod sursa (job #3130878) | Cod sursa (job #278629) | Cod sursa (job #556009) | Cod sursa (job #1938348) | Cod sursa (job #1998701)
#include <iostream>
#include <fstream>
#define nmax 15
using namespace std;
ifstream fin("damesah.in");
ofstream fout("damesah.out");
int x[nmax],n; ///back
bool viz[nmax],ds[nmax],dp[nmax];
int nr; ///nr sol
void Write()
{int i;
for(i=1;i<=n;i++)
fout<<x[i]<<" ";
fout<<endl;
}
inline int mod(int x)
{if(x<0) return -x;
return x;}
void Back(int k)
{int i;
for(i=1;i<=n;i++)
if(viz[i]==0&&ds[k-i+1]==0&&dp[n-k+i]==0)
{x[k]=i; viz[i]=ds[k-i+1]=dp[n-k+1]=1;
if(k==n)
{nr++;
if(nr==1) Write();
}
else Back(k+1);
viz[i]=ds[k-i+1]=dp[n-k+1]=0;
}
}
int main()
{fin>>n;
Back(1);
fout<<nr<<endl;
return 0;
}