Cod sursa(job #3195867)

Utilizator Radu_MocanasuMocanasu Radu Radu_Mocanasu Data 21 ianuarie 2024 21:59:48
Problema Problema Damelor Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.8 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("damesah.in");
ofstream fout("damesah.out");
int n,col,d1,d2;
int rez;
int st[15];
inline void print(){
    for(int i = 1; i <= n; i++) fout << st[i] << " ";
    fout << "\n";
}
void backt(int k){
    if(k > n){
        if(!rez) print();
        rez++;
    }
    for(int i = 1; i <= n; i++){
        if(!(col & (1 << i)) && !(d1 & (1 << (i + k))) && !(d2 & (1 << (i - k + n)))){
            st[k] = i;
            col ^= (1 << i);
            d1 ^= (1 << (i + k));
            d2 ^= (1 << (i - k + n));
            backt(k + 1);
            col ^= (1 << i);
            d1 ^= (1 << (i + k));
            d2 ^= (1 << (i - k + n));
        }
    }
}
int main()
{
    fin >> n;
    backt(1);
    fout << rez;
    return 0;
}