-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboardcover.cpp
76 lines (60 loc) · 1.82 KB
/
boardcover.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
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
// X X X X X X X X X X X X
// X O O X O O X O X X O X
// X O X X X O O O X X O O
const int shapes[4][3][2] = {{{0, 1}, {0, 0}, {1, 0}}, {{0, 0}, {1, 0}, {1, 1}}, {{0, 0}, {0, 1}, {-1, 1}}, {{0, 0}, {0, 1}, {1, 1}}};
bool set(int x, int y, int type, int delta, vector<vector<int>>& board) {
bool ret = true;
for (int i = 0; i < 3; ++i) {
const int tx = x + shapes[type][i][0];
const int ty = y + shapes[type][i][1];
if (tx < 0 || tx >= board[0].size() || ty < 0 || ty >= board.size())
return false;
else if ((board[ty][tx] += delta) > 1)
ret = false;
}
return ret;
}
int solve(vector<vector<int>>& board) {
int x, y;
for (y = 0; y < board.size(); ++y) {
for (x = 0; x < board[0].size(); ++x) {
if (board[y][x] == 0)
break;
}
if (x != board[0].size())
break;
}
if (y == board.size())
return 1;
int result = 0;
for (int type = 0; type < 4; type++) {
if (set(x, y, type, 1, board))
result += solve(board);
set(x, y, type, -1, board);
}
return result;
}
int main()
{
int numTestCase, height, width;
cin >> numTestCase;
for (int i = 0; i < numTestCase; i++) {
cin >> height >> width;
vector<vector<int>> board(height, vector<int>(width, 0));
for (int j = 0; j < height; j++) {
for (int k = 0; k < width; k++) {
char target;
cin >> target;
if (target == '#')
board[j][k] = 1;
}
}
cout << solve(board) << endl;
}
return 0;
}