luogu#P8187. [USACO22FEB] Robot Instructions S
[USACO22FEB] Robot Instructions S
题目描述
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 .
题目大意
题目描述
贝西正在学习如何控制她最近作为礼物收到的机器人。
机器人初始在坐标平面上的点 ,Bessie 希望机器人在点 停止。 Bessie 最初有一个包含 条指令的指令列表给机器人,其中第 个指令将向右移动机器人 单位和向上移动 单位(或者当 和 为负数时分别向左或向下移动)。
对于从 到 的每个 ,帮助 Bessie 计算她可以从原始 中选择 条指令的方案数,使得在执行 条指令后,机器人将在点 处停止。
输入格式
第一行包含 。下一行包含 和 ,每个数都在 的范围内。最后的 行描述了指令。每行有两个整数 和 ,也在 范围内。
保证 和对于所有的 。
数据范围
数据 满足 。
数据 无额外约束。
样例解释
在此示例中,Bessie 可以通过六种方式选择指令:
(-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)
对于第一种方式,机器人的路径如下所示:
$(0,0) \to (-2,0) \to (1,0) \to (5,0) \to (5,10) \to (5,0) \to (5,10)$
7
5 10
-2 0
3 0
4 0
5 0
0 10
0 -10
0 10
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.