Mine layer (2008 World final C)

Source: Internet
Author: User

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:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.