Eggplant Field Path
Time limit1sMemory limit1024 MB
Count the distinct ways a monotone lattice path from (0,0) to (R,C) can split the planted branches into upper and lower sets without touching any branch.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Math
- Solved
- No attempts yet
Problem
The eggplant field is a rectangular grid with rows and columns. Two lattice points at distance are joined by a segment-shaped path. Every morning, Bamgo leaves for work from the top left point and walks to the bottom right point using exactly segments. Some lattice points have cute branches planted on them, so Bamgo cannot pass through those points.
Bamgo has walked this field every day and believes that some routes across it are effectively the same. When the route Bamgo walked cuts the grid into two regions, some points lie in the upper region and the rest lie in the lower region. Two routes are the same if every branch falls in the same region, upper or lower, under both routes. How many distinct routes does Bamgo think there are?
See the note for the exact definition of the two cut regions.
Input
The first line contains three integers , , and , separated by spaces. and are the height and width of the rectangular grid, and is the number of planted branches.
Each of the next lines contains two integers and , separated by a space, giving the position of a planted branch.
All branch coordinates are distinct, and there are no branches at or .
Output
On the first line, print the number of distinct routes according to Bamgo, modulo the prime .
Hints
The exact definition of the two regions is as follows.
- If the route Bamgo walked passes through , the upper region is the whole set and the lower region is the empty set.
- Otherwise, if the route passes through , the lower region is the whole set and the upper region is the empty set.
- In all other cases, the region containing is called the lower region, and the region containing is called the upper region.