-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1033.cpp
More file actions
43 lines (33 loc) · 705 Bytes
/
1033.cpp
File metadata and controls
43 lines (33 loc) · 705 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
36
37
38
39
40
41
42
43
#include <iostream>
#include <string>
using namespace std;
const int mx[4] = { 0, 1, 0, -1 };
const int my[4] = { 1, 0, -1, 0 };
const int N = 34;
char mat[N][N];
bool v[N][N];
int n;
bool Prov(int i, int j) {
if (i < 0 || i >= n) return 0;
if (j < 0 || j >= n) return 0;
return 1;
}
int dfs(int i, int j) {
if (!Prov(i, j) || mat[i][j] == '#')
return 1;
if (v[i][j])
return 0;
v[i][j] = 1;
int res = 0;
for (int k = 0; k < 4; k++)
res += dfs(i + mx[k], j + my[k]);
return res;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> mat[i];
int p;
p = dfs(n - 1, n - 1)+ dfs(0, 0) - 4;
cout << p*9;
}