QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 1024 MB 總分: 100

#4970. 熊猫寻宝箱

统计

我们最喜欢的寻宝猎人 Panda 被投放到一个二维迷宫中,迷宫里有几个宝箱。每个迷宫单元格要么是空的,要么包含一个宝箱。宝箱里装有钱,且没有两个宝箱的金额相同,即所有宝箱的金额各不相同。Panda 只能拥有其中一个宝箱,显然他更想要金额最高的那个,但他可能没有足够的能量到达装有该宝箱的单元格,因此 Panda 可能不得不退而求其次,选择金额较低的宝箱。

题目描述

Panda 开始时拥有一定的能量。右图显示了 Panda 移动到八个相邻单元格中任意一个所需的能量(注意,迷宫边界单元格的邻居少于八个)。

为了说明移动所需的能量,如果 Panda 想向上移动,需要 2 单位能量;如果他想向下移动,需要 6 单位能量。

如果 Panda 移动到一个有宝箱的单元格,他就会得到那个宝箱,也就是说,即使 Panda 还有剩余能量可以进行更多移动,旅程也结束了。显然,Panda 只有在拥有足够能量进行该次移动时才能移动。当 Panda 进行移动时,他的能量会相应地减少。

你需要确定 Panda 能获得的最大金额。注意,Panda 不必用完他所有的能量,也就是说,如果 Panda 在拿到宝箱时还有剩余能量,这是允许的。

输入格式

第一行包含五个整数:

  • $R_m$ ($2 \le R_m \le 500$),表示迷宫的行数;
  • $C_m$ ($2 \le C_m \le 500$),表示迷宫的列数;
  • $R_p$ ($1 \le R_p \le R_m$),表示 Panda 起始位置的行号;
  • $C_p$ ($1 \le C_p \le C_m$),表示 Panda 起始位置的列号;以及
  • $E_p$ ($1 \le E_p \le 10^6$),表示 Panda 的起始能量。

假设 Panda 的起始位置是有效的(即在迷宫内),且该单元格不包含宝箱。

接下来的 $R_m$ 行,每行包含 $C_m$ 个整数(每个整数在 $0$ 到 $10^6$ 之间,含边界)。每行输入描述迷宫中的一行,提供单元格内容。零表示该单元格没有宝箱;非零值表示有宝箱(宝箱中的金额)。假设迷宫中至少有一个宝箱,并且 Panda 有足够的起始能量到达至少一个宝箱。

输出格式

输出 Panda 能获得的最大金额。

样例

输入格式 1

4 3 2 1 15
0 0 0
0 0 0
0 0 10
0 20 0

输出格式 1

10

输入格式 2

4 3 2 3 50
0 0 0
0 0 0
0 0 10
0 20 0

输出格式 2

20

输入格式 3

4 2 1 1 90
0 0
0 0
10 30
40 50

输出格式 3

30

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.