Cod sursa(job #1098457)

Utilizator enedumitruene dumitru enedumitru Data 4 februarie 2014 20:29:49
Problema Problema Damelor Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.59 kb
#include<fstream>
#include<cmath>
using namespace std;
ifstream f("damesah.in"); ofstream g("damesah.out");
short n,k,nr,x[15];
inline void afis()
{	nr++;
	if(nr==1)
	{	for(short i=1;i<=n;++i) g<<x[i]<<' ';
		g<<'\n';
	}
}
inline bool cont(int k)
{ 	for(short i=1;i<k;++i) 
		if(x[i]==x[k]) return 0;
			else if(k-i==abs(x[k]-x[i])) return 0;
	return 1;
}
void back()
{	k=1; x[k]=0;
	do	{	while(x[k]<n)
				{	x[k]++;
					if(cont(k))
						if(k==n) afis(); else x[++k]=0;
				}
			k--;
		}
	while(k);
}
int main()
{	f>>n; 
	back();
	g<<nr<<'\n'; g.close(); return 0;
}