I have been searching for a long time. I have learned a bit about the search idea from the original rote memorization, but it is actually quite good, I have summarized several methods for deep search in the graph for reference only:
First, we need to know what deep search is, and then what is the difference between wide search. And which templates
For example, red and black: This is the most common question for beginners. What we need to consider for this question isThe number,Find the @ location for this question:
for(int i=0;i<m;i++){ for(int j=0;j<n;j++) { if(map[i][j]=='@') }}
After finding it, You can happily search for it from this point. Then we should talk about the difference between deep search and wide search. If you find this point, if it is a wide search, it will start from its side to search, however, unlike deep search, it only searches for his son nodes until the boundary is reached, or
'#', And the next step isMark, which can be said to be necessary for Deep Search, mark it to prevent re-entry into the loop. The last step is recursion. As you can imagine, when you have no way to go, you certainly go home or look around for a path. It can be said that it is a deep search like "don't hit the south wall, don't look back".
if(tx>=0&&tx<m-1&&ty>=0&&ty<n-1&&map[tx][ty]=='*'); { sum++; map[tx][ty]; dfs(tx,ty); }
Template:
I. The first thing we need is the direction. There are many directions. I will gradually improve this article later. For image search, it is nothing more than a four-direction and eight-direction, to build a two-dimensional array, you need to understand other words;
2: finding a boundary
3: The image is lost.
Summary:
Question list:
1) hangdian:
2) poj:
To be continued