Similar to mine clearance games, some mines are walking in some grids. The specific burial position is unclear, but the total number of mines in each grid and the eight grids around it is known. Which line in the middle can have a maximum number of mines (the question assumes that all inputs are odd rows )?
Restrictions
Input column C with the R row
Small
R = 3, 5
3 ≤ C ≤ 5
Large
3 ≤ r ≤ 49, r is an odd number
3 ≤ C ≤ 49
Example 1
Input
R = 3, C = 3
2 2 1
3 4 3
2 3 2
Output
1 (the distribution of mines is only shown on the right)
Example 2
Input
R = 3, C = 3
The information of each grid is as follows:
2 2 1
3 4 3
2 3 2
Output
1 (corresponding to the example diagram in the topic description)
Analysis:
This question starts from a simple situation.
One-dimensional situations:
Each grid has a number, but the specific number is unknown. However, we know the sum of the numbers in the two adjacent grids.
The sum of numbers in a one-dimensional lattice: 4 8 9 8 6 6 5
Number in one-dimensional lattice: 2 2 4 3 1 2 3
The remainder of Model 3 is classified as follows: