-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueen.cpp
More file actions
35 lines (31 loc) · 852 Bytes
/
queen.cpp
File metadata and controls
35 lines (31 loc) · 852 Bytes
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
#include <iostream>
#include <string>
using namespace std;
int ans = 0;
bool takencols[8] , takendiag1[16], takendiag2[16];
void place(string board[8] , int r, int &ans) {
if (r == 8) {
ans++;
return;
}
for (int c = 0; c < 8; c++) {
if (board[r][c] == '.') {
if (!takencols[c] && !takendiag1[r - c + 8 - 1] && !takendiag2[r + c]) {
takencols[c] = takendiag1[r - c + 8 - 1] = takendiag2[r + c] = true;
place(board, r + 1, ans);
takencols[c] = takendiag1[r - c + 8 - 1] = takendiag2[r + c] = false;
}
}
}
}
int main() {
string b;
string board[8];
int ans = 0;
for (int i = 0; i < 8; i++) {
cin >> board[i];
}
place(board , 0, ans);
cout << ans;
return 0;
}