深度优先搜索模型:
void dfs(int step)
{
判断边界
尝试每一种可能 for(i=1;i<=n;i++)
{
继续下一步 dfs(step+1);
}
返回
}
对于深度优先搜索,首先要明白当前怎么做,然后直接dfs(step+1),做下一步即可。
BFS:
通常用来解决最小路径,最少操作类问题,
void dfs(int step)
{
判断边界
尝试每一种可能 for(i=1;i<=n;i++)
{
继续下一步 dfs(step+1);
}
返回
}
对于深度优先搜索,首先要明白当前怎么做,然后直接dfs(step+1),做下一步即可。
通常用来解决最小路径,最少操作类问题,
Author: 💤ISpiker
Permalink: https://hehelv.github.io//post/dfsdepth-first-search
License: MIT License