Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- N, M = map(int, input().split())
- plan = [None] * (N + 1)
- a = [[None] * M for t in range(N)]
- for l in range(N):
- plan[l] = list(map(int, input().split()))
- for k in range(N):
- if plan[k][1] != 0 and a[k - 1][1] != 0:
- a[k][1] = 1
- else: a[k][1] = 0
- for t in range(M):
- if plan[1][t] != 0 and a[1][t - 1] != 0:
- a[1][t] = 1
- else: a[1][t] = 0
- for i in range(2, N):
- for j in range(2, M):
- if plan[i][j - 1] != 0 and plan[i - 1][j] != 0:
- a[i][j] = a[i][j - 1] + a[i - 1][j]
- elif plan[i][j - 1] == 0 and plan[i -1][j] != 0:
- a[i][j] = a[i - 1][j]
- elif plan[i][j - 1] != 0 and plan[i -1][j] == 0:
- a[i][j] = a[i][j - 1]
- elif plan[i][j - 1] == 0 and plan[i -1][j] == 0:
- a[i][j] = 0
- if a[N - 1][M - 1] != 0:
- print(a[N - 1][M - 1])
- else: print('Impossible')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement