网站备案期间做网页,百度指数1000搜索量有多少,怎么制作外贸网站,西丽网站的建设第十一章#xff1a;图论part01
图论理论基础
大家可以在看图论理论基础的时候#xff0c;很多内容 看不懂#xff0c;例如也不知道 看完之后 还是不知道 邻接矩阵#xff0c;邻接表怎么用#xff0c; 别着急。
理论基础大家先对各个概念有个印象就好#xff0c;后面在…第十一章图论part01
图论理论基础
大家可以在看图论理论基础的时候很多内容 看不懂例如也不知道 看完之后 还是不知道 邻接矩阵邻接表怎么用 别着急。
理论基础大家先对各个概念有个印象就好后面在刷题的过程中每个知识点都会得到巩固。 https://www.programmercarl.com/kamacoder/%E5%9B%BE%E8%AE%BA%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80.html
深搜理论基础
了解一下深搜的原理和过程 https://www.programmercarl.com/kamacoder/%E5%9B%BE%E8%AE%BA%E6%B7%B1%E6%90%9C%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80.html
98. 所有可达路径
https://www.programmercarl.com/kamacoder/0098.%E6%89%80%E6%9C%89%E5%8F%AF%E8%BE%BE%E8%B7%AF%E5%BE%84.html
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;public class Main {static ListListInteger result new ArrayList(); // 收集符合条件的路径static ListInteger path new ArrayList(); // 1节点到终点的路径public static void dfs(int[][] graph, int x, int n) {// 当前遍历的节点x 到达节点nif (x n) { // 找到符合条件的一条路径result.add(new ArrayList(path));return;}for (int i 1; i n; i) { // 遍历节点x链接的所有节点if (graph[x][i] 1) { // 找到 x链接的节点path.add(i); // 遍历到的节点加入到路径中来dfs(graph, i, n); // 进入下一层递归path.remove(path.size() - 1); // 回溯撤销本节点}}}public static void main(String[] args) {Scanner scanner new Scanner(System.in);int n scanner.nextInt();int m scanner.nextInt();// 节点编号从1到n所以申请 n1 这么大的数组int[][] graph new int[n 1][n 1];for (int i 0; i m; i) {int s scanner.nextInt();int t scanner.nextInt();// 使用邻接矩阵表示无向图1 表示 s 与 t 是相连的graph[s][t] 1;}path.add(1); // 无论什么路径已经是从1节点出发dfs(graph, 1, n); // 开始遍历// 输出结果if (result.isEmpty()) System.out.println(-1);for (ListInteger pa : result) {for (int i 0; i pa.size() - 1; i) {System.out.print(pa.get(i) );}System.out.println(pa.get(pa.size() - 1));}}
}广搜理论基础
https://www.programmercarl.com/kamacoder/%E5%9B%BE%E8%AE%BA%E5%B9%BF%E6%90%9C%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80.html