-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chessboard and Queens.cpp
65 lines (62 loc) · 1007 Bytes
/
Chessboard and Queens.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int k=0;
int board[8][8];
char c[8][8];
bool Possible(int x, int y)
{
if(c[x][y]=='*') return false;
for(int l=0;l<x;l++)
{
if(board[l][y]==1) return false;
}
int i=x;
int j=y;
while(i>=0 and j >=0)
{
if(board[i][j]==1) return false;
i--;j--;
}
i=x;j=y;
while(i>=0 and j<8)
{
if(board[i][j]==1) return false;
i--;
j++;
}
return true;
}
void solve(int i)
{
if(i==8)
{
k++;
return;
}
for(int j=0;j<8;j++)
{
if(Possible(i,j))
{
board[i][j]=1;
solve(i+1);
}
board[i][j]=0;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
for(int i=0;i<8;i++)
{
for(int j=0;j<8;j++)
{
board[i][j]=0;
cin>>c[i][j];
}
}
solve(0);
cout<<k;
}