Commute Route
InterviewTime limit1sMemory limit128 MB
Count monotone east/north lattice paths from (1,1) to (a,b) that avoid n blocked intersections, with a and b at most 16.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Combinatorics, Array, Matrix
- Solved
- No attempts yet
Problem
Taro lives in JOI City, which is divided into a grid by roads running straight in the north–south direction and roads running straight in the east–west direction.
The north–south roads are numbered from west to east. The east–west roads are numbered from south to north. The intersection where the -th north–south road (from the west) meets the -th east–west road (from the south) is denoted .
Taro lives near intersection and commutes by bicycle to JOI High School, which is near intersection . The bicycle can move only along the roads. To shorten his commute, Taro always moves only toward the east or the north.
Currently, construction is underway at intersections , and Taro cannot pass through an intersection that is under construction.
How many ways can Taro commute from intersection to intersection , moving only east or north while avoiding every intersection under construction? Write a program that computes the number of commute routes .
Input
The first line contains two integers and , separated by a space, giving the number of north–south roads and the number of east–west roads, respectively. They satisfy .
The second line contains an integer , the number of intersections under construction, satisfying .
Each of the following lines gives the position of an intersection under construction: the -th such line contains two space-separated integers and , indicating that intersection is under construction. They satisfy .
Output
Print a single line containing only , the number of Taro's commute routes.
Hint
The figure below shows the case , , , where the intersections under construction are , , and .

In this case there are commute routes. All five routes are illustrated below.
