#P1958. 上学路线

上学路线

Description

The streets in your city form a grid, with aa north–south streets and bb east–west streets. The aa north–south streets are numbered from west to east as 11 to aa, and the bb east–west streets are numbered from south to north as 11 to bb. The intersection of north–south street ii and east–west street jj is denoted as (i,j)(i,j).

You live at (1,1)(1,1), and the school is at (a,b)(a,b). You ride a bicycle to school, which can travel only along the streets, and to minimize time you are only allowed to move east or north.

Now NN intersections are under construction, (X1,Y1)(X_1, Y_1), (X2,Y2)(X_2, Y_2), …, (XN,YN)(X_N, Y_N), and these intersections are closed to traffic.

How many different routes are there to go to school?

Input Format

The first line contains two integers aa and bb, with 1a,b161 \le a, b \le 16. It is guaranteed that the school is not at (1,1)(1,1), and that the destination is reachable.

The second line contains an integer NN, indicating that there are NN intersections under construction (1N401 \le N \le 40).

The next NN lines each contain two integers Xi,YiX_i, Y_i, giving the locations of the closed intersections.

Output Format

Output a single integer, the total number of routes from (1,1)(1,1) to (a,b)(a,b).

5 4
3
2 2
2 3
4 2
5

Hint

Translated by ChatGPT 5