-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.py
33 lines (31 loc) · 891 Bytes
/
solution.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
# Paths finding approach
def solution1():
m, n = [int(input()), int(input())]
t = (n - 1, m - 1)
rows = [input() for _ in range(m)]
v = 0
queue=[(0,0)]
while len(queue) > 0:
x, y = queue.pop(0)
nx, ny = [x + 1, y + 1]
if t in [(nx, y), (x, ny)]:
v = v + 1;continue
if nx < n and rows[y][nx] == '0':
queue.append((nx, y))
if ny < m and rows[ny][x] == '0':
queue.append((x, ny))
print(v)
# Dynamic approach
def solution2():
m, n = [int(input()), int(input())]
tb = [[0] * n for _ in range(m) ]
tb[0][0] = 1
for y in range(m):
raw = [int(c) for c in input()]
for x in range(n):
if raw[x]: continue
if y > 0:
tb[y][x] += tb[y-1][x]
if x > 0:
tb[y][x] += tb[y][x-1]
print(tb[m-1][n-1])