1. 程式人生 > >Avoid The Lakes (深搜dfs)

Avoid The Lakes (深搜dfs)

Farmer John's farm was flooded in the most recent storm, a fact only aggravated by the information that his cows are deathly afraid of water. His insurance agency will only repay him, however, an amount depending on the size of the largest "lake" on his farm.

The farm is represented as a rectangular grid with N

(1 ≤ N ≤ 100) rows andM (1 ≤ M ≤ 100) columns. Each cell in the grid is either dry or submerged, and exactlyK (1 ≤ KN × M) of the cells are submerged. As one would expect, a lake has a central cell to which other cells connect by sharing a long edge (not a corner). Any cell that shares a long edge with the central cell or shares a long edge with any connected cell becomes a connected cell and is part of the lake.