#P7301. [USACO21JAN] Spaced Out S
[USACO21JAN] Spaced Out S
Description
Farmer John wants to take a photo of his cows grazing and hang it on the wall. The field can be represented as an by square grid (imagine an chessboard), where . In Farmer John’s recent photos, his cows were too concentrated in one area of the field. This time, he wants to make sure his cows are spread out across the entire field, so he insists on the following rules:
- No two cows may be in the same cell.
- Every submatrix (there are of them) must contain exactly 2 cows.
For example, this placement is valid:
CCC
...
CCC
But this placement is invalid, because the bottom-right square contains only 1 cow:
C.C
.C.
C..
There are no other restrictions. You may assume Farmer John has infinitely many cows (based on past experience, this seems to be true...).
Farmer John also prefers some cells to contain cows. Specifically, he believes that if a cow is placed in cell , the beauty of the photo increases by units ().
Find the maximum total beauty over all valid cow placements.
Input Format
The first line contains . The next lines each contain integers. From top to bottom, the -th integer on the -th line is the value of .
Output Format
Output one integer: the maximum beauty of the resulting photo.
4
3 3 1 1
1 1 3 1
3 3 1 1
1 1 3 3
22
Hint
In this sample, the maximum beauty can be achieved with the following placement:
CC..
..CC
CC..
..CC
The beauty of this placement is .
Testdata properties:
- Test cases 2-4 satisfy .
- Test cases 5-10 satisfy .
- Test cases 11-20 satisfy .
Problem by: Hankai Zhang, Danny Mittal.
Translated by ChatGPT 5
京公网安备 11011102002149号