#P4474. 王者之剑
王者之剑
Description

This is before Artoria Pendragon became a Heroic Spirit. She is about to pull the sword from the stone to become King Arthur, and before that she needs to collect some gems.
The gems are arranged in an grid. Each cell contains a gem worth . Artoria Pendragon may choose her own starting cell.
The initial time is seconds. The following operations are executed every second, in order.
- At the beginning of second , if Artoria Pendragon is on cell , she can take the gem in .
- At even-numbered seconds, the gems in the four orthogonally adjacent cells around Artoria Pendragon disappear.
- If Artoria Pendragon is on cell at the beginning of second , then at second she may immediately move to , , , or , or stay at .
Find the maximum total value of gems that Artoria Pendragon can obtain.
Input Format
The first line gives the numbers , representing the number of rows and columns. . The value of each gem does not exceed . The next lines and columns describe the value matrix.
Output Format
Output the maximum total value of gems that can be taken.
2 2
1 2
2 1
4
Hint
An original problem by Yao Jinyu.
Translated by ChatGPT 5
京公网安备 11011102002149号