logo AlgoBeat OnlineJudge
登录 注册

#207527. [USACO22FEB] Robot Instructions S

内存限制:512 MiB 时间限制:4000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Bessie is learning how to control a robot she has recently received as a gift. The robot begins at point on the coordinate plane and Bessie wants the robot to end at point . Bessie initially has a list of instructions to give to the robot, the -th of which will move the robot units right and units up (or left or down when and are negative, respectively).

For each from to , help Bessie count the number of ways she can select instructions from the original such that after the instructions are executed, the robot will end at point .

Note: the time and memory limits for this problem are 4s and 512MB, twice the defaults.

输入格式

The first line contains . The next line contains and , each in the range . The final lines describe the instructions. Each line has two integers and , also in the range .

It is guaranteed that and for all .

输出格式

Print lines, the number of ways Bessie can select instructions from the original for each from to .

样例

样例输入 1

7
5 10
-2 0
3 0
4 0
5 0
0 10
0 -10
0 10

样例输出 1

0
2
0
3
0
1
0

数据范围与提示

【样例解释】

In this example, there are six ways Bessie can select the instructions:

(-2,0) (3,0) (4,0) (0,10) (0,-10) (0,10) (1 2 3 5 6 7)
(-2,0) (3,0) (4,0) (0,10) (1 2 3 5)
(-2,0) (3,0) (4,0) (0,10) (1 2 3 7)
(5,0) (0,10) (0,-10) (0,10) (4 5 6 7)
(5,0) (0,10) (4 5)
(5,0) (0,10) (4 7)

For the first way, the robot's path looks as follows:

(0,0) -> (-2,0) -> (1,0) -> (5,0) -> (5,10) -> (5,0) -> (5,10)

【数据范围】

  • Test cases 2-4 satisfy .
  • Test cases 5-16 satisfy no additional constraints.