Pagini recente » damesah | damesah | Borderou de evaluare (job #3361204) | damesah | Cod sursa (job #3365797)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("damesah.in");
ofstream fout("damesah.out");
int n, p[15], c[30], dp[30], ds[30], sol;
void back(int lin)
{
if (lin == n + 1)
{
sol++;
if (sol == 1)
for (int i = 1; i <= n; i++)
fout << p[i] << " ";
fout << '\n';
return;
}
for (int col = 1; col <= n; col++)
{
if(c[col]) continue;
if(dp[n + lin - col]) continue;
if (ds[lin + col]) continue;
p[lin] = col;
c[col] = 1;
dp[n + lin - col] = 1;
ds[lin + col] = 1;
back(lin + 1);
c[col] = 0;
dp[n + lin - col] = 0;
ds[lin + col] = 0;
}
}
int main()
{
fin >> n;
back(1);
fout << sol << '\n';
}