Cod sursa(job #2428002)

Utilizator AlexNeaguAlexandru AlexNeagu Data 3 iunie 2019 13:20:43
Problema Problema Damelor Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.28 kb
#include<bits/stdc++.h>
#pragma gcc optimize("O3")
#define all(s) s.begin(),s.end()
#define rc(x) return cout<<x<<endl,0
#define forn(i,n) for(int i=0;i<int(n);i++)
#define len(a) (int) (a).size()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
typedef long long ll;
typedef std::vector < ll > vl;
typedef std::vector < int > vi;
typedef std::vector < std:: pair < int, int > > vii;
typedef long double ld;
const int nmax=0;
const int mod=1e9+7;
const ll inf=0x3f3f3f3f3f3f3f3f;
using namespace std;
ifstream fin("damesah.in");
ofstream fout("damesah.out");
int n, cnt = 0;
bool col[50], d1[50], d2[50];
vi v;
void print()
{
  for (int i = 0; i < v.size(); i ++)
  fout << v[i] << " ";
  fout << "\n";
}
void search(int y)
{
  if (y == n + 1)
  {
    if (cnt == 0) print();
    cnt++;
  }
  for (int x = 1; x <= n; x++) {
  if (col[x] || d1[x + y] || d2[x - y + n - 1])
  continue;
  col[x] = d1[x + y] = d2[x - y + n - 1] = 1;
  v.pb(x); search(y + 1);
  col[x] = d1[x + y] = d2[x - y + n - 1] = 0;
  v.pop_back();
}
}
int main()
  {
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    fin >> n;
    search(1);
    fout << cnt;
    return 0;
  }