Chessboard
Time limit2sMemory limit512 MB
Count the pairs of non-meeting lattice paths from (1,1) to (N,M) on a board with K forbidden cells, where the first moves are fixed, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Combinatorics, Dynamic programming, Math
- Solved
- No attempts yet
Problem
A chessboard has cells. Rows are numbered from top to bottom, and columns are numbered from left to right. Cell is in row and column . The board has forbidden cells. Neither nor is forbidden.
Pieces and start at and move together, one cell at a time, toward under these rules.
- A piece at can move to or . A move that leaves the board is not allowed.
- At the start, piece moves from to , and piece moves from to .
- While moving, the two pieces must not meet on any cell except and .
- Neither piece can move onto a forbidden cell.
Following these rules, count the pairs of paths that take pieces and from to , where is the path of piece and is the path of piece .
Input
The first line contains , , and , separated by spaces. (, )
Each of the next lines contains the row number and column number of a forbidden cell, separated by a space. No cell is given twice. (, , , )
All numbers in the input are integers.
Output
Print the number of path pairs that let pieces and start together at and reach , modulo .