php algorithm-- catching water droplets
A novice PHP programmer, who has been on the job for half a year and is still hovering in endless additions, deletions, modifications and data optimization, has recently been brought into the algorithm pit by the front-end brother and has done a lot of algorithm problems.
this question comes from the collar buckle network, which is more interesting.
given a matrix of m x n, in which the values are all positive integers, representing the height of each cell in the two-dimensional height map, please calculate the maximum volume of Rain Water in the figure.
description:
m an dna re integers less than 110. The height of each unit is greater than 0 and less than 20000.
example:
the height map of 3x6 is given as follows:
[
[1 br > [1 br 4],
[3 br 2],
[3 br >]
returns 4.
[[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]
after it rains, Rain Water will be stored in these squares. The total amount of rain water received is 4.
my idea is:
the volume that can receive water is the volume of each layer that is vacant, but some of the volume of the vacancy is notched. So the specific idea:
1.
2.
3. = -
4.
I don"t know if there is a better idea.