dp
with tuples of (0, 0)
for each cell in the board.dp[n-1][n-1]
to (0, 1)
as the starting point with a score of 0 and 1 path.(i, j)
, if it is not an obstacle, calculate the maximum score from the adjacent cells that can be reached (down, right, and diagonally down-right).dp[i][j]
with the new maximum score and the sum of the number of paths from the adjacent cells that lead to this maximum score, modulo 10^9 + 7
.'E'
, do not add its numeric value to the score.dp
array, the answer will be in dp[0][0]
.[0, 0]
.