深度优先搜索就是利用递归方法搜素,得到结果。
深度优先搜索解决问题的框架:
void dfs(int deep, State curState)
{
if (deep > Max) //深度达到极限
{
if (curState == target) //找到目标
{
//...
}
}
else
{
for (i = 1; i <= totalExpandMethod; i++)
{
dfs(deep + 1,
expandMethod(curState, i));
}
}
}