33 行代码C++算法模板
图的邻接矩阵 DFS 搜索模板
DFS 搜索无权图中从起点到终点的简单路径数量(邻接矩阵)
#include <bits/stdc++.h>
using namespace std;
const int N = 1005; // 根据题目点的数量范围调整
int g[N][N]; // 邻接矩阵,g[u][v] = 1 表示有边
bool vis[N];#图#dfs#邻接矩阵
DFS 搜索无权图中从起点到终点的简单路径数量(邻接矩阵)
#include <bits/stdc++.h>
using namespace std;
const int N = 1005; // 根据题目点的数量范围调整
int g[N][N]; // 邻接矩阵,g[u][v] = 1 表示有边
bool vis[N];DFS 搜索无权图中从起点到终点的简单路径数量(邻接表)
#include <bits/stdc++.h>
using namespace std;
const int N = 1005; // 根据题目点的数量范围调整
vector<int> adj[N]; // 邻接表(有权图需要使用结构体)
bool vis[N];DFS 搜索二维矩阵中从 (1, 1) 到 (n, m) 的路线数量
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};