QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 256 MB Points totaux : 100

#12210. 跳跃限制

Statistiques

兔子非常喜欢跳跃。跳跃之后她会感到快乐。

有一个 $M$ 行 $N$ 列的矩形网格。令 $(x, y)$ 表示第 $x$ 行第 $y$ 列的单元格($1 \le x \le M, 1 \le y \le N$)。她现在站在单元格 $(X_S, Y_S)$ 上,想要前往单元格 $(X_T, Y_T)$。当她位于单元格 $(x, y)$ 时,可以执行以下四种移动之一:

  • 向上跳跃(Up-jump)—— 跳到单元格 $(x - 1, y)$,并获得 $A_{x-1, y}$ 点快乐值。
  • 向下跳跃(Down-jump)—— 跳到单元格 $(x + 1, y)$,并获得 $A_{x+1, y}$ 点快乐值。
  • 向左跳跃(Left-jump)—— 跳到单元格 $(x, y - 1)$,并获得 $A_{x, y-1}$ 点快乐值。
  • 向右跳跃(Right-jump)—— 跳到单元格 $(x, y + 1)$,并获得 $A_{x, y+1}$ 点快乐值。

然而存在一个限制:向上跳跃、向下跳跃、向左跳跃和向右跳跃分别最多只能执行 $L_{Up}$ 次、$L_{Down}$ 次、$L_{Left}$ 次和 $L_{Right}$ 次。

兔子不能跳出网格范围。她的最后一次跳跃必须落在单元格 $(X_T, Y_T)$。注意,她可以多次访问同一个单元格,即使是 $(X_S, Y_S)$ 或 $(X_T, Y_T)$,并且每次落入该单元格时都能获得相应的快乐值。编写一个程序,计算她能获得的最大总快乐值。

输入格式

输入格式如下:

$M \ N$ $X_S \ Y_S \ X_T \ Y_T$ $L_{Up} \ L_{Down} \ L_{Left} \ L_{Right}$ $A_{1,1} \ A_{1,2} \ \dots \ A_{1,N}$ $\vdots$ $A_{M,1} \ A_{M,2} \ \dots \ A_{M,N}$

第一行包含两个整数 $M$ 和 $N$ ($1 \le M \le 50, 1 \le N \le 50$)。第二行包含四个整数 $X_S, Y_S, X_T$ 和 $Y_T$ ($1 \le X_S \le M, 1 \le Y_S \le N, 1 \le X_T \le M, 1 \le Y_T \le N$)。单元格 $(X_S, Y_S)$ 和 $(X_T, Y_T)$ 是不同的。第三行包含四个整数 $L_{Up}, L_{Down}, L_{Left}$ 和 $L_{Right}$ ($0 \le L_{Up} \le 50, 0 \le L_{Down} \le 50, 0 \le L_{Left} \le 50, 0 \le L_{Right} \le 50$)。接下来的 $M$ 行中,第 $x$ 行包含 $N$ 个整数,其中第 $y$ 个整数为 $A_{x,y}$ ($0 \le A_{x,y} \le 10^6$)。

输出格式

如果兔子无法到达 $(X_T, Y_T)$,输出整数 $-1$。否则,输出一个整数:她能获得的最大总快乐值。

样例

输入 1

2 3
1 1 2 3
1 2 0 2
10 50 30
40 80 20

输出 1

280

输入 2

2 3
1 1 2 3
1 2 1 1
10 50 30
40 80 20

输出 2

-1

输入 3

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

输出 3

77

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.