Pagini recente » Atasamentele paginii againfminostress | Profil ovi_pas | Profil AlenCaSosuGlen | Cod sursa (job #1276985) | Cod sursa (job #2013732)
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
ifstream in("damesah.in");
ofstream out("damesah.out");
vector<int> solutii;
vector<bool> col(14,false);
vector<bool> diag1(28,false);
vector<bool> diag2(28,false);
bool checked = false;
int count = 0;
int n;
void search(int y)
{
if(y == n)
{
if(checked == false)
{
for(auto var : solutii)
out << var + 1 << ' ';
checked = true;
}
count++;
}
for(int i = 0; i < n; i++ )
{
if(col[i]|| diag2[i+n-y-1] || diag1[i+y])
continue;
solutii.push_back(i);
col[i] = diag1[i+y] = diag2[i+n-y-1] = true;
search(y+1);
col[i] = diag1[i+y] = diag2[i+n-y-1] = false;
solutii.pop_back();
}
}
int main()
{
in >> n;
search(0);
out <<'\n';
out << count;
return 0;
}