摘要: 1.要用剪枝,在排列过程中判断当前排列是否合法,如果不合法直接停止,直接回溯 1 import java.util.*; 2 public class Main{ 3 static int n;//输入 4 static char[][] path=new char[20][20];//路径 5 / 阅读全文
posted @ 2022-04-08 20:56 经典的错误 阅读(83) 评论(0) 推荐(0)
摘要: 并查集 用树来表示每一个集合,根节点编号就是这个集合的编号,每一个点都存储它的父节点p[x]是谁,如何找到元素属于哪个集合?一直找他的父节点,直到根结点,根结点编号就是它的集合 除了根节点之外,x的父节点都不等于x,根节点的父节点就是根结点 如何优化问题2? 一旦找到根结点,将路径上所有点都指向根结 阅读全文
posted @ 2022-04-07 22:09 经典的错误 阅读(135) 评论(0) 推荐(0)
摘要: 栈和队列 栈的实现 tt指向栈顶,tt初始值为0 队列实现 hh为队头,tt为队尾,tt初始值为负一,在队尾插入元素,在队头弹出元素 1 import java.util.*; 2 public class Main{ 3 static int stk[]=new int[100010]; 4 st 阅读全文
posted @ 2022-04-06 18:33 经典的错误 阅读(39) 评论(0) 推荐(0)
摘要: 作用: 1.数组模拟单列表-邻接表:存储图和树 2.双列表:优化问题 单链表实现和操作 e[n]存value,ne[n]存next指针,-1表示尾结点 1 import java.util.*; 2 public class Main{ 3 static int head; 4 static int 阅读全文
posted @ 2022-04-05 22:53 经典的错误 阅读(76) 评论(0) 推荐(0)
摘要: import java.util.Scanner; public class Main { static int N = 1010; static int a[][] = new int[N][N]; //b为a的差分数组 static int b[][] = new int[N][N]; publ 阅读全文
posted @ 2022-04-04 09:52 经典的错误 阅读(84) 评论(0) 推荐(0)
摘要: import java.io.InputStreamReader;import java.util.Scanner; public class Main { static long result=0; public static void merge_sort(int q[],int l,int r 阅读全文
posted @ 2022-04-03 19:20 经典的错误 阅读(36) 评论(0) 推荐(0)
摘要: import java.util.Scanner;public class Main { //该数组用来临时存放左半边和右半边数组的数据 static int[] temp=new int[100010]; public static void merge_sort(int q[],int l,in 阅读全文
posted @ 2022-04-03 19:19 经典的错误 阅读(27) 评论(0) 推荐(0)