Pagini recente » Cod sursa (job #807755) | Cod sursa (job #1606884) | Cod sursa (job #2894770) | Cod sursa (job #589567) | Cod sursa (job #2650769)
#include <bits/stdc++.h>
using namespace std;
ifstream in("damesah.in");
ofstream out("damesah.out");
int n;
long long written = 0;
int pozs[15];
int mask_col[30];
int mask_d1[30];
int mask_d2[30];
void bkt(int row)
{
if(row == n)
{
if(written == 0)
{
for(int i = 0; i < n; i++)
out << pozs[i]+1 << " ";
out << endl;
}
written++;
}
for(int col = 0; col < n; col++)
{
if(mask_col[col] == 0 && mask_d1[row + col] == 0 && mask_d2[n - row + col] == 0)
{
mask_col[col] = 1;
mask_d1[row + col] = 1;
mask_d2[n - row + col] = 1;
pozs[row] = col;
bkt(row+1);
mask_col[col] = 0;
mask_d1[row + col] = 0;
mask_d2[n - row + col] = 0;
}
}
}
int main()
{
in >> n;
bkt(0);
out << written;
}