#P3356. 火星探险问题
火星探险问题
Description
The lander of the Mars exploration team will touch down on the Martian surface. Inside the lander, there are multiple obstacle-detecting rovers. After landing, the rovers will leave the lander and move toward the transmitter that arrived earlier.
While moving, the rovers must also collect rock samples. Each rock sample is collected by the first rover that encounters it. Each rock sample can be collected only once. After a rock sample is collected, other rovers may pass through its former location. Rovers cannot pass through obstructed terrain.
In this problem, rovers are limited to moving from the landing position toward the transmitter only in the south or east direction, and multiple rovers may occupy the same position at the same time. If any rover cannot proceed before reaching the transmitter, all rock samples it collected will be lost.
Use a grid to represent the positions between the lander and the transmitter. The lander is at , and the transmitter is at .
$$\begin{bmatrix} (x_1,y_1) & (x_2,y_1) & \dots & (x_{p-1},y_1) & (x_p,y_1) \\ (x_1,y_2) & (x_2,y_2) & \dots & (x_{p-1},y_2) & (x_p,y_2) \\ \dots & \dots & \dots & \dots & \dots \\ (x_1,y_{q-1}) & (x_2,y_{q-1}) & \dots & (x_{p-1},y_{q-1}) & (x_p,y_{q-1}) \\ (x_1,y_q) & (x_2,y_q) & \dots & (x_{p-1},y_q) & (x_p,y_q) \end{bmatrix}$$Given the state of each position, compute the optimal movement plan so that the number of rovers reaching the transmitter is maximized, and the number of rock samples collected by the rovers is also maximized.
Input Format
The first line contains the number of rovers . The next two lines contain and , respectively.
The next lines describe the grid of positions between the lander and the transmitter. Three numbers are used to represent the state of a position: means flat and unobstructed, means an obstacle, and means a rock.
Output Format
Each line contains a rover ID and one movement direction, where means moving south and means moving east.
2
10
8
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 0 0 0
0 0 0 1 0 2 0 0 0 0
1 1 0 1 2 0 0 0 0 1
0 1 0 0 2 0 1 1 0 0
0 1 0 1 0 0 1 1 0 0
0 1 2 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0
1 1
1 1
1 1
1 1
1 0
1 0
1 1
1 1
1 1
1 1
1 0
1 0
1 1
1 0
1 0
1 0
2 1
2 1
2 1
2 1
2 0
2 0
2 0
2 0
2 1
2 0
2 0
2 1
2 0
2 1
2 1
2 1
Hint
Constraints For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号