Nazi is back and will be eliminating some Jews. Both Nazi and the Jews lived in an n × n grid. Initially Nazi is located at the cell (r, c) where r is the row number and c is the column number both starting from 1, with r=1 is the bottom row. Each cell (i, j) denoted as grid[i][j] can be either 0 or 1, where 0 indicates the absence of Jews and 1 means presence. Nazi can move to any of the adjacent cells from it's current cell each time, as long as it does not goes out of the border. Find the number of ways Nazi can eliminate all the Jews.
Constraints:
1<=n<=10
1<=r,c<=n
grid[i][j]=0 or grid[i][j]=1, 1<=i,j<=n
Example:
Input:
n=2
r=1, c=1
grid={{0, 1},
{0, 0}}
Output:
3
Explanation:
Nazi can eliminate the only Jew located at (2, 2) in the following 3 ways:
- Move up 1 unit, then move right 1 unit
((1,1)->(2,1), (2,1)->(2,2)) - Move right 1 unit, then move up 1 unit
((1,1)->(1,2), (1,2)->(2,2)) - Move diagonally up-right 1 unit
((1,1)->(2,2))