package test;
public class DFS {
final static int MAXN = 100;
static boolean vst[][] = new boolean[MAXN][MAXN];
static int dir[][] = new int[][] { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } };
static int map[][] = new int[MAXN][MAXN];
static void dfs(int x, int y) {
vst[x][y] = true;
if (map[x][y] == G) { //G为边界条件
return ;
}
for (int i = 0; i < 4; i++) {
int tx = x + dir[i][0];
int ty = y + dir[i][1];
if (checkEdge(tx, ty)) {
dfs(tx, ty);
}
}
}
static boolean checkEdge(int x,int y) {
if (!vst[x][y]) {
return true;
}
return false;
}
public static void main(String[] args) {
}
}
DFS深度优先搜索模板
最新推荐文章于 2025-06-24 21:41:59 发布