Home > other >  Recursive traversal grid, meet the first return will end the recursion, rather than a return to a la
Recursive traversal grid, meet the first return will end the recursion, rather than a return to a la

Time:05-27

The code is as follows:
 
@ tail_call_optimized
Def DFS (independence idx, imsize, LBL) :
If not inarea (independence idx imsize) :
Return False

If hydro_band [independence idx [0], independence idx [1]].=LBL:
Return False

Hydro_band [independence idx [0], independence idx [1]]=0
Mark (independence idx imsize, LBL)

DFS ([independence idx [0] 1, independence idx [1]], imsize, LBL)
DFS ([independence idx [0], independence idx + 1] [1], imsize, LBL)
DFS ([independence idx [0] + 1, independence idx [1]], imsize, LBL)
DFS ([independence idx [0], independence idx] [1] - 1, imsize, LBL)
Return True


Figure is just a sketch, encountered for the first time beyond the scope of the grid or value is not 1 grid, return will end the recursion, rather than a return to a layer, namely four DFS, the following 3 don't perform, is this why?
  • Related