#P3189. [HNOI2007] 海盗分宝
[HNOI2007] 海盗分宝
Description
It is said that after each raid, if there are valuables such as gold, silver, and jewels, the Caribbean pirates divide the loot with a special ceremony.
They first pack the jewels into earthenware cubes with side length , and mark the value of the jewels on the lid. Then they arrange these boxes into a rectangle of length and width (if the jewels are not enough, empty earthenware boxes may be used to fill the empty positions and are marked with value ). The value marked on the box at row and column is (where , ; the box at the lower-left corner is at row , column ).
According to their contributions, the pirates decide an order for picking treasures. The pirate whose turn it is will be given a wooden crate with a base of and height , and is required to fill the crate with the selected earthenware boxes, then close the crate lid.
The boxes must be selected in batches. Each batch must be a contiguous rectangular region equal to the crate’s base, and the side of the crate of length must be parallel to the side of the arranged rectangle that has length . The positions of the selected boxes are immediately filled with empty boxes after removal. The pirate starts from the exact center of the bottom edge of the arranged rectangle, i.e., from the lower-right corner of the box at row and column , and proceeds upward along the vertical line that is the left edge of column of the arranged rectangle.
As shown by the bold arrows in the figure. Let the lower-left corner of the -th selected region be the box at row , column . The index must satisfy $\lfloor \frac{m}{2} + j_k - \frac{w}{2} \rfloor \leq a$, where . Moreover, when , must satisfy ; when , must satisfy , where .

Input Format
The first line contains eight positive integers separated by single spaces: . From the second line to line , each line contains integers. Denote the integer in row , column by (, ), representing the jewel value marked on the box lid. The integers on the same line are separated by single spaces.
Note: In the input, starts from the top-left box, but for the problem definition the box at the lower-left corner is at row , column .
Output Format
Output a single integer on the first line: the maximum total jewel value that can be obtained.
10 12 3 2 3 5 2 3
0 0 0 1 0 1 1 1 9 1 1 1
1 1 2 1 1 1 0 0 8 2 1 8
1 0 1 0 1 6 1 1 0 0 1 1
1 1 2 1 2 1 1 1 3 1 1 1
0 1 0 1 1 1 2 1 6 0 2 1
1 1 0 1 0 1 1 2 1 1 1 0
1 0 1 1 1 0 1 0 1 1 0 1
1 1 0 1 1 1 9 0 0 1 1 1
0 0 1 0 1 2 1 9 1 1 0 1
0 1 1 1 1 1 9 1 1 1 1 1
59
Hint
, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号