Greetings everyone,
Problem Statement
You are given a grid with N rows and M columns. This grid contains some vacant spaces represented by 0 and boxes represented by 1. You are initially at cell (1,1), and at any cell, you can move either right or down. While moving right or down, you can push a box in the same direction as you are moving as long as all the boxes in front of you remain in the grid boundaries.
Task
Determine the number of ways to go from the cell (1,1) to the cell (N, M). Since the answer can be very large, so print the answer modulo 10^9 + 7.
Notes
Example 1
Assumptions
Approach
Therefore, there is only one way and so the output is 1.
Example 2
Approach
Given below are the two ways out of 5 possible ways for the given grid. Here, c represents your current position on the way to (4,4).
c 0 0 1 0 c 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1
0 1 1 0 0 1 1 0 0 c 1 0 0 0 c 1 0 0 0 1 0 0 0 1 0 0 0 1
0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 c 0 0 1 0 c 0 1 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 0 0 1 1 0 0 1 1 cc 0 0 1 0 c 0 1 0 0 c 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1
0 1 1 0 0 1 1 0 0 1 1 0 0 1 c 0 0 1 0 c 0 1 0 0 0 1 0 0
0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 c 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 cExample 3
This question maybe the extension of unique paths II problem. Tried to preprocess the grid to convert it into fixed obstacles & then count the paths, but struggling to do so. Is this the right way, is there any better approach?
Thanks in advance.