#P4012. 深海机器人问题

    ID: 2945 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>O2优化图的建立,建图最大流费用流网络流 24 题

深海机器人问题

Description

The submarine of a deep-sea resource exploration team will arrive at the ocean floor for scientific investigation.

There are multiple deep-sea robots inside the submarine. After reaching the seafloor, the robots will leave the submarine and move toward their predetermined targets.

While moving, the robots must collect biological specimens along the way. Each specimen along the route is collected by the first robot that encounters it.

The value of specimens on each prescribed path (i.e., each grid edge) is known, and each specimen can be collected at most once.

In this problem, each robot may move only to the north or to the east from its current position. Multiple robots may occupy the same position at the same time.

The movable positions of the robots are represented by a P×QP \times Q grid. The southwest corner has coordinates (0,0)(0,0), and the northeast corner has coordinates (Q,P)(Q,P).

Given the starting positions and destination positions of each robot, as well as the specimen values on each grid edge, compute the optimal movement plan that maximizes the total value of collected specimens after all robots reach their destinations.

Input Format

The first line contains the number of starting locations aa and the number of destination locations bb.

The second line contains the values of PP and QQ.

The next P+1P+1 lines each contain QQ positive integers. In the ii-th line (0-indexed), the jj-th (0-indexed) integer gives the specimen value on the edge from (i,j)(i,j) to (i,j+1)(i,j+1).

The next Q+1Q+1 lines each contain PP positive integers. In the ii-th line (0-indexed), the jj-th (0-indexed) integer gives the specimen value on the edge from (j,i)(j,i) to (j+1,i)(j+1,i).

The next aa lines each contain three positive integers k,x,yk, x, y, indicating that there are kk robots starting from position (x,y)(x,y).

The next bb lines each contain three positive integers r,x,yr, x, y, indicating that there are rr robots that may choose position (x,y)(x,y) as a destination.

Output Format

Output the maximum total value of collected specimens.

1 1
2 2
1 2
3 4
5 6
7 2
8 10
9 3
2 0 0
2 2 2
42

Hint

1P,Q151 \leq P, Q \leq 15.

1a41 \leq a \leq 4.

1b61 \leq b \leq 6.

Translated by ChatGPT 5