#P8230. [AGM 2022 资格赛] 地牢
[AGM 2022 资格赛] 地牢
Problem Description
Danny is a hardcore fan of Dungeon Crawlers. Recently, he wanted to know whether a computer can play this game, and he wants you to help him test it.
The game has levels. Each level contains cells. A cell can be one of the following types:
-
0represents an empty cell. -
-1represents an exit to the next level. After entering the next level, your initial position is at the location of this exit. Except for the last level which has no exit, each level has exactly one exit. -
-9represents an impassable obstacle. -
xis an integer , representing an enemy's power value.
To defeat an enemy, your power value must be greater than or equal to its power value. After defeating it, your own power value increases by an amount equal to the defeated enemy's power value. You may move to the four adjacent cells (up, down, left, right). If a cell contains an enemy, you must defeat it to pass through. Exits are forced teleports: you cannot step onto an exit without being teleported.
Assume your initial power value is . You start from at the top-left corner of the first level, and you finish the game at any position on the last level. What is the maximum power value you can reach? The testdata guarantees that there is always a path to the last level.
Input Format
The first line contains three integers .
Then follow matrices. Each matrix has rows and columns, consisting of integers describing the type of each cell.
It is guaranteed that the value at position is 0.
Output Format
Output one integer, representing the answer.
1 5 5
0 0 0 0 1
0 0 0 0 0
0 0 1 0 0
0 0 0 0 1
5 0 0 0 0
4
2 5 5
0 0 -9 0 1
0 0 -9 -9 -9
0 0 1 0 0
0 0 -1 0 1
4 0 0 0 0
0 0 0 0 1
0 0 0 0 0
0 0 3 0 0
0 0 0 0 1
5 0 0 0 0
13
Hint
Constraints
For of the testdata, it is guaranteed that .
Notes
Translated from AGM 2022 Qualification Round B Dungeon。
Translated by ChatGPT 5