文理学院程序设计在线练习


Walking on the Grid II

Time Limit: 3 Second(s)    Memory Limit: 32 MB

Total Submission(s): 21   Accepted Submission(s): 9
Problem Description

Biving lives in Grid Kingdom, which is a special country as all its cities lie in a grid of size W*H.
Biving’s home locates in grid(1, 1) and she wants to go to grid(W, H) as soon as possible. In each step, she can walk from grid(I, J) to grid(I+1, J) or grid(I, J+1), but she can never walk out of the grid. Meanwhile, there are some dangerous cities which Biving can’t walk into. We will make sure that grid(1, 1) and grid(W, H) will not be dangerous.
Here comes the question, how many paths Biving can choose to achieve her goal. Two paths Pi and Pj are treat as different if there exist some step Pi going to grid(x, y) but Pj not.

Input

The input contains multiple test cases (<= 100).
The first line of each test case contains three integer W, H and D (1<=W<=30, 1<=H<=1,000,000,000, 0<=D<=min(W*H-2, 50) ).Then follow D lines, each line contains a coordinate (X, Y) of a dangerous grid(city) (1<=X<=W, 1<=Y<=H).

Output

For each case, output the path’s number modulo 1,000,000,007 in a single line.

Sample Input
2 2 0
2 3 1
2 2
3 5 2
2 2
3 4
Sample Output
2
1
3
Source

2013绍兴市赛