7009.Grid Paths II

Time Limit: 1s Memory Limit: 512MB

Consider an $n \times n$ grid whose top-left square is $(1,1)$ and bottom-right square is $(n,n)$ .

Your task is to move from the top-left square to the bottom-right square. On each step you may move one square right or down. In addition, there are $m$ traps in the grid. You cannot move to a square with a trap.

What is the total number of possible paths?

Input Format(From the terminal/stdin)

The first input line contains two integers $n$ and $m$ : the size of the grid and the number of traps.

After this, there are $m$ lines describing the traps. Each such line contains two integers $y$ and $x$ : the __cpLocation of a trap.

You can assume that there are no traps in the top-left and bottom-right square.

  • $1 \le n \le 10^6$
  • $1 \le m \le 1000$
  • $1 \le y,x \le n$

Output Format(To the terminal/stdout)

Print the number of paths modulo $10^9+7$ .

Sample Input

Copy
3 1
2 2
 · \n
 · \n

Sample Output

Copy
2
 \n
Source: CSES, Counting Problems, 1078

Submit

请先 登录

© 2025 FAQs