-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipe1.py
69 lines (63 loc) · 1.47 KB
/
pipe1.py
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
n = int(input())
mapp = []
for i in range(n):
mapp.append(list(map(int, input().split(' '))))
cnt = 0
def dfs(loc, dir):
global cnt
x, y = loc
if (x, y) == (n-1, n-1):
cnt += 1
if dir == 1 :
#오른쪽으로
y += 1
if y < n:
if mapp[x][y] == 0:
dfs([x, y], 1)
y -= 1
# 오른쪽아래로
x += 1
y += 1
if x<n and y<n:
if mapp[x][y] == 0 and mapp[x-1][y] == 0 and mapp[x][y-1] == 0:
dfs([x, y], 2)
x -= 1
y -= 1
if dir == 2 :
#오른쪽으로
y += 1
if y < n:
if mapp[x][y] == 0:
dfs([x, y], 1)
y -= 1
# 오른쪽아래로
x += 1
y += 1
if x<n and y<n:
if mapp[x][y] == 0 and mapp[x-1][y] == 0 and mapp[x][y-1] == 0:
dfs([x, y], 2)
x -= 1
y -= 1
#아래로
x += 1
if x < n:
if mapp[x][y] == 0:
dfs([x, y], 3)
x -= 1
if dir == 3 :
# 오른쪽아래로
x += 1
y += 1
if x<n and y<n:
if mapp[x][y] == 0 and mapp[x-1][y] == 0 and mapp[x][y-1] == 0:
dfs([x, y], 2)
x -= 1
y -= 1
#아래로
x += 1
if x < n:
if mapp[x][y] == 0:
dfs([x, y], 3)
x -= 1
dfs((0, 1), 1)
print(cnt)