P27412 [AtCoder] square1001's School Road
提高
题目描述

Problem Description

square1001 goes to school on foot every day.

He lives at the bottom-left intersection $ (1,1) $ and goes to his school at the top-right intersection $ (W,H) $.

However, there are the following conditions:

  • He only moves right or up to save time.
  • On that day, he had $ K $ errands to run at $ K $ squares. The bottom-left corner of these squares is $ (X_i,Y_i) $, and the top-right corner is $ (X_i+1,Y_i+1) $. Therefore, for each square with an errand, he needs to pass at least one of the four surrounding intersections.

How many ways are there to satisfy these conditions? Find the answer modulo $ 1,000,000,007 $.

Input Format

The input is given from the standard input in the following format:

$ H $ $ W $ $ K $ $ X_1 $ $ Y_1 $ $ X_2 $ $ Y_2 $ : : $ X_K $ $ Y_K $

  • The first line contains integers $H\ (1≦H≦1,000)$, $ W(1≦W≦1,000) $, and $ K(1≦K≦200) $ separated by spaces.
  • The next $ K $ lines contain integers $X_i\ (1≦X_i<W)$ and $Y_i\ (1≦Y_i<H)$ separated by spaces.

Output Format

Output the number of ways to satisfy the conditions in one line.

Sample Input and Output

Sample Input #1

4 4 1
2 2

Sample Output #1

18

Sample Input #2

9 9 3
3 2
4 5
7 7

Sample Output #2

4380

Notes/Hints

Sample Explanation 1

The paths $ (1,1)→(1,2)→(1,3)→(1,4)→(2,4)→(3,4)→(4,4) $ and $ (1,1)→(2,1)→(3,1)→(4,1)→(4,2)→(4,3)→(4,4) $ are not possible. Therefore, output $ 20-2=18 $. Sorry for the missing number in the top-left corner of the diagram.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 4 1 2 2
样例输出
18