随笔分类 - 数据结构与算法
摘要:CPP代码 点击查看代码 #include <iostream> #include <queue> #include <stack> using namespace std; // 多叉树节点 struct Node { string name; // 节点名称 vector<Node*> node
阅读全文
摘要:1. 快速排序 🤠 原题链接 🤠 快速排序+选择性递归 🤠 O( 2n ) import java.util.*; class Main{ static int N = 1010; static int[] q = new int[N]; public static void main(Str
阅读全文
摘要:一、动态规划 1. 01背包问题 🤠 思路 🤠 二维数组dp 🤠 参考传送门 🤠 时间 O( nm ) 空间 O( nm ) /* 输入案例 输出 8 4 5 1 2 2 4 3 4 4 5 */ static int N = 1010; static int[][] f = new int
阅读全文
摘要:一、搜索与图论 1. DFS(深度优先遍历) 😋 时间复杂度: 邻接矩阵:O(v^2) (v是点数) 邻接表: O(v+m) (v是点数,m是边数) 😋 数字排列 static int n = 10; static int[] path = new int[15]; // 存储数字的顺序 sta
阅读全文
摘要:一、基础算法 1. BufferReader改善scanner读取慢的问题 😋 比较麻烦的一点就是readLine() 的返回值是 String ,读取整型的时候需要强转 😋 write 不能直接输出 int 类型,得加一个字符或者转换成字符串 public static void main(S
阅读全文