A courier crosses a vault floor laid out as a grid of H rows and W columns of cells, starting at the top-left cell (row 1, column 1) and ending at the bottom-right cell (row H, column W), moving only right (east) or down (south) one cell per step. One cell contains a trap and must never be stepped on. Count the number of monotone routes that avoid the trap cell. Report the count modulo 1000000007.
Line 1: two integers H and W.
Line 2: two integers br and bc, the 1-indexed row and column of the trap cell.
A single integer: the number of trap-avoiding routes, modulo 1000000007.
Example 1
Input
3 3 2 2
Expected
2
Explanation
Total routes C(4,2)=6; routes through the center (2,2) number 2*2=4; so 6-4=2 avoid it.
Example 2
Input
2 2 1 2
Expected
1
Explanation
Of the 2 routes on a 2x2 grid, one passes through (1,2); the other avoids it, so the answer is 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →