Pagini recente » Cod sursa (job #3151213) | Cod sursa (job #3276294) | Cod sursa (job #2452020) | Cod sursa (job #2944351) | Cod sursa (job #1593996)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("damesah.in");
ofstream g("damesah.out");
int x[100], use[100], n, nr, gasit;
int valid()
{
for(int i = 2; i <= n; ++i)
{
for(int j = 1; j < i; ++j)
if((x[i] - x[j] == i-j) || (x[i] - x[j] == -1*(i-j)))
{
return 0;
}
}
return 1;
}
void show()
{
for(int i = 1; i <= n; ++i)
g << x[i] << ' ';
g << '\n';
}
void backk(int k)
{
do
{
if(valid())
{
nr++;
if(!gasit)
show(), gasit = 1;
}
}
while(next_permutation(x+1,x+n+1));
}
int main()
{
f >> n;
for(int i = 1; i <= n; ++i)
x[i] = i;
backk(1);
g << nr;
}