Travel in CodeLand
Bob wants to travel across CodeLand. CodeLand is a form of rectangular grid with N rows and M
columns. Each grid is a city. Bob has to travel from City(1,1) to City(N,M). City(i,j) represents city
located at ith row and ſth column. Bob arrives in a new city everyday, parks his car in parking lot and
takes a taxi to travel in the city. There are P(ij) parking lots in city Cli,j). Bob can use any one of them.
If Bob is in City(ij) then he can travel to any City(i+x, j+y) provided:
x > O and x = y OR
• X = 0 and y> O OR
• x>and y=0.
Can you tell Bob in how many different number of ways can he can park his car in Parking Lot while
traveling from City(1,1) to City(N,M). This number can be very large, so calculate it modulo 109+7.
NOTE: Two ways are considered different if there is at-least one parking lot in the first set and not in the
second set.
INPUT
ROG
HO
F
PERSE
The first line contains two space-separated integers N and M.
The next N lines each contain M numbers separated by a space.
The ith value in ith line denotes Pipi e number of parking lots in City(ij).
Answers
Answered by
10
Answer:
Explanation:
In this question there are n*m across the entire codeland city. And in the every city parking lot are there. These are i*j nos of them. For the first realism of this state we have to consider a n*m 2d matrix where every index will represent a grid and inside them there has to be the designated parking spots.
According to the question when the iteration is going on here that means Bob is traveling across all the city in codeland. He can either move row major wise or column major wise. When he is in city (i, j) he can be in any parking spot.
Now when he chooses to move to city(i+x, j+y)
He has to follow these various conditions
x>0 and y=0 or x=0 and y>0.
Similar questions