Question - You have to find the number of ways you can reach from the intial position (1,1) to the final position (N,M) [where N is the number of rows and M is the number of columns], given that:
- You can move any number of steps downwards.
- You can move any number of steps towards the right.
Note: Here the array indices are 1-indexed
Some conditions:
- You can never move out of the grid.
- You cannot ignore the conditions.
- The first cell (1,1) and the last cell (N,M) do not contain obstacles.
- A free cell is denoted by . and an obstacle is denoted by *.
Sample test case:
>>> 3 3
. . .
. * .
. . .
>>> 8
There will be 8 ways:
- (1,1),(1,2),(1,3),(2,3),(3,3)
- (1,1),(1,2),(1,3),(3,3)
- (1,1),(1,3),(2,3),(3,3)
- (1,1),(1,3),(3,3)
- (1,1),(2,1),(3,1),(3,2),(3,3)
- (1,1),(3,1),(3,2),(3,3)
- (1,1),(2,1),(3,1),(3,3)
- (1,1),(3,1),(3,3)
My code:
def ways(l):
# Don't know how to proceed
Testcases=int(input())
lst=[]
for i in range(Testcases):
N,M=input().split()
N,M=int(N),int(M)
for j in range(N):
s=input().split(" ",M)
lst.append(s)
ways(lst)
I have no idea how to proceed.