Huawei OD machine test - looking for the most valuable mine pile (Java & JS & Python)

topic description

Give you a map consisting of '0' (open space), '1' (silver mine), and '2' (gold mine). The ore pile can only be formed by connecting gold mines or silver mines adjacent up, down, left, and right. Areas beyond the scope of the map can be considered vacant land.

Assuming that the value of the silver mine is 1 and the value of the gold mine is 2, please find the ore heap with the largest value on the map and output the value of the ore heap.

enter description

Map element information such as:

22220
00000
00000
11111

  • Map range up to 300*300
  • 0 ≤ map elements ≤ 2

output description

The maximum value of the ore pile

Example

enter 22220
00000
00000
01111
output 8
illustrate none

Guess you like

Origin blog.csdn.net/qfc_128220/article/details/130774841