Pagini recente » Cod sursa (job #1918104) | Cod sursa (job #3132261) | Cod sursa (job #1160490) | Cod sursa (job #1327990) | Cod sursa (job #3192821)
#include <bits/stdc++.h>
#define C 20
using namespace std;
ifstream fin("damesah.in");
ofstream fout("damesah.out");
int n, dp[2*C], ds[2*C], markcol[C], sol[C], nr;
void bkt(int l) {
if (l>n) {
nr++;
if (nr==1) {
for (int i=1; i<=n; i++) fout<<sol[i]<<' ';
fout<<'\n';
}
}
else {
for (int c=1; c<=n; c++) {
int DS=l+c;
int DP=l-c+n;
if (ds[DS]==0 && markcol[c]==0 && dp[DP]==0) {
sol[l]=c;
ds[DS]=1;
markcol[c]=1;
dp[DP]=1;
bkt(l+1);
ds[DS]=0;
markcol[c]=0;
dp[DP]=0;
}
}
}
}
int main()
{
fin>>n;
bkt(1);
fout<<nr;
return 0;
}