DFS——C++

 dfs称为深度优先搜索是一种搜索算法。

具体算法讲解可以参考

https://blog.csdn.net/qq_63055790/article/details/133961017

DFS——C++_第1张图片

例题:https://www.acwing.com/activity/content/problem/content/905/

#include
using namespace std;

const int N=10;
int n;
int path[N];
bool st[N];

void dfs(int u)
{
    if(u==n)
    {
        //已经遍历完成
        for(int i=0;i

例题:https://www.acwing.com/activity/content/problem/content/906/

#include
using namespace std;

const int N=20;
char q[N][N];
bool con[N],du[N],ndu[N];
int n;

void dfs(int u)
{
    //边界结束情况
    if(u==n)
    {
        for(int i=0;i>n;
    for(int i=0;i

 

你可能感兴趣的:(深度优先,c++,算法)