Cod sursa(job #2770445)

Utilizator bubblegumixUdrea Robert bubblegumix Data 21 august 2021 00:16:24
Problema Problema Damelor Scor 90
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include<fstream>
using namespace std;
int sol[100], nr;
int n;

ifstream f("damesah.in");
ofstream g("damesah.out");

void tipar()
{
	
}
inline bool isValid(int k)
{
	
			return false;
	return true;
}

void back(int k)
{
	for (int i = 1; i <= n; i++)
	{
		sol[k] = i;
		int ok = 1;
		for (int i = 1; i < k; i++)
			if (abs(k - i) == abs(sol[k] - sol[i]) || sol[i] == sol[k])
				ok = 0;
		if (ok)
			if (k == n )
			{
				nr++;
				if (nr == 1)
				{
					for (int i = 1; i <= n; i++)
						g << sol[i] << ' ';
					g << '\n';
				}
			}
			else
				back(k + 1);
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	f.tie(0);
	g.tie(0);
	f >> n;
	back(1);
	g << nr;
}