-
Notifications
You must be signed in to change notification settings - Fork 0
/
maze.py
60 lines (49 loc) · 1.2 KB
/
maze.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
def check(mat, i, j, n):
if i < 0 or j < 0 or i >= n or j >= n or mat[i][j] == 0:
return False
return True
def find(mat, i, j, n, sol, target):
if (i, j) == target:
sol[i][j] = 1
return True
if check(mat, i, j, n):
sol[i][j] = 1
ds = [(1,0), (0, 1), (-1, 0), (0, -1)]
if find(mat, i+1, j, n, sol, target):
return True
if find(mat, i, j+1, n, sol, target):
return True
if find(mat, i-1, j, n, sol, target):
return True
if find(mat, i, j-1, n, sol, target):
return True
# for d in ds:
# i, j = i + d[0], j + d[1]
# if find(mat, i, j, n, sol, target):
# return True
sol[i][j] = 0
return False
return False
####################################
mat = []
for j in range(6):
a_mat = [int(i) for i in input().split()]
mat.append(a_mat)
n = len(mat)
sol = [[0 for _ in range(n)] for _ in range(n)]
if find(mat, 0, 0, n, sol, (n-1, n-1)):
for i in range(n):
print(sol[i])
'''
1 1 0 1 1
0 1 1 1 1
0 0 0 0 1
1 0 1 1 1
1 0 1 0 1
1 0 1 1 1 0
1 0 1 0 1 0
1 0 1 0 1 0
1 0 1 0 1 0
1 1 1 0 1 1
0 0 0 0 0 1
'''