#P7311. [COCI 2018/2019 #2] Maja
[COCI 2018/2019 #2] Maja
Description
The bee Maja is pollinating flowers in a magical meadow. The meadow can be represented as an matrix. In row and column , there are unpollinated flowers.
Maja starts from the beehive located at row and column , travels to some areas of the meadow, and then returns. In step, Maja can move from the current area to an adjacent area (the area to the left, right, above, or below), but it will not leave the meadow. Each time Maja passes through an area, it pollinates all currently unpollinated flowers in that area. But the meadow is magical: after Maja leaves area , all pollinated flowers there disappear, and then unpollinated flowers immediately grow back.
Since Maja cannot fly forever, it will get tired after steps. What is the maximum number of flowers Maja can pollinate while starting from the hive and returning to it within steps?
Input Format
The first line contains positive integers .
The next lines each contain integers, where the value for area is the number of flowers .
No flowers grow in the area where the beehive is located.
Output Format
Output the maximum number of flowers Maja can pollinate while starting from the hive and returning to it within steps.
2 2 1 1 2
0 1
2 10
2
2 2 1 1 4
0 5
5 10
20
3 3 2 2 6
5 1 0
1 0 3
1 3 3
15
Hint
Sample 1 Explanation
Maja starts at , first flies downward to pollinate flowers, and then returns.
Sample 2 Explanation
Maja starts at and flies right, down, up, and left in order. Since Maja passes through twice, each time it passes, it can pollinate flowers.
Constraints
For of the testdata, .
For of the testdata, , , , , , and .
Notes
The score of this problem follows the original COCI setting, with a full score of .
This problem is translated from COCI2018-2019 CONTEST #2 T4 Maja.
Translated by ChatGPT 5
京公网安备 11011102002149号