Kundrapu N.

asked • 07/21/17

Island thunder strikes

There is an island in the Pacific Ocean and it receives heavy rainfall every year. It is also highly prone to thunder strikes during the monsoon.

The houses in the island are in connected blocks. The connected patterns in the houses are indicated as in the picture below. Here, 1 denotes a house and 0 denotes empty space.



Two houses are said to be connected if they are neighbors to each other. By neighbor we mean that they are adjacent to each other in one of the directions Up, Down, Left, Right.



As it is highly prone to thunder strikes, if a thunder strikes one region then all the houses in that region gets destroyed. The whole island is mapped by a M by N matrix of 0, 1s.
For example,



You are given a fixed number of thunder strikes, say n. Write a program to find the maximum number of houses that would be destroyed by the strikes.

Input

A line containing comma separated integers N, M indicating the size of the island

A line containing L, the number of thunder strikes on the island

N lines each containing M integers each of which s 0 or 1

Mark M.

No picture below!
Report

07/21/17

1 Expert Answer

By:

Andy C. answered • 07/22/17

Tutor
4.9 (27)

Math/Physics Tutor

Andy C.

Yes, I have a working recursive java routine which counts the number of houses destroyed
and updates the 2D array accordingly.
 
The input data is hard-coded for now. File Input and random number
generation is the next step.
 
Report

07/22/17

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.