🛸~~ 🚁🚁🚁🛩️🛩️🛩️~|

n1ce2cv

园龄:5年2个月粉丝:4关注:1

随笔分类 -  算法

多重背包、混合背包
摘要:title: 多重背包、混合背包 date: 2024-10-21 01:02:21 +0800 categories: [algorithm, problems] tags: [Algorithm, Knapsack problem, Monotonic Queue] description: 多
4
0
0
分组背包、完全背包
摘要:title: 分组背包、完全背包 date: 2024-10-21 01:18:02 +0800 categories: [algorithm, problems] tags: [Algorithm, Knapsack problem] description: 分组背包、完全背包 分组背包:多个物
18
0
0
01背包、有依赖的背包
摘要:title: 01背包、有依赖的背包 date: 2024-10-20 10:47:00 +0800 categories: [algorithm, problems] tags: [Algorithm, Knapsack problem] description: 01背包、有依赖的背包 P104
9
0
0
KMP
摘要:title: KMP date: 2024-10-19 10:30:44 +0800 categories: [algorithm, summary] tags: [Algorithm, KMP] description: KMP s1 字符串是否包含 s2 字符串,如果包含返回 s1 中包含 s2
11
0
0
质数判断、质因子分解、质数筛
摘要:title: 质数判断、质因子分解、质数筛 date: 2024-10-17 10:37:23 +0800 categories: [algorithm, summary] tags: [Algorithm, Prime number] description: 质数判断、质因子分解、质数筛 判断质
12
0
0
字符串哈希
摘要:字符串哈希 哈希函数的基本性质: 1)输入参数的可能性是无限的,输出的值范围相对有限 2)输入同样的样本一定得到同样的输出值,也就是哈希函数没有任何随机机制 3)输入不同的样本也可能得到同样的输出值,此时叫哈希碰撞 4)输入大量不同的样本,得到的大量输出值,会几乎均匀的分布在整个输出域上 base
24
0
0
最长递增子序列
摘要:最长递增子序列 300. 最长递增子序列 普通解法 #include <vector> using namespace std; class Solution { public: // 时间复杂度 O(n^2) int lengthOfLIS(vector<int> &nums) { int n =
5
0
0
子数组最大累加和(下)
摘要:子数组最大累加和(下) 152. 乘积最大子数组 #include <vector> #include <algorithm> using namespace std; class Solution { public: int maxProduct(vector<int> &nums) { int
11
0
0
二分答案法
摘要:二分答案法 估计最终答案的大概范围 分析问题的答案和给定条件之间的单调性 建立一个 f 函数,当答案固定的情况下,判断给定的条件是否达标 在最终答案可能的范围上不断二分搜索,每次用 f 函数判断,直到二分结束,找到最合适的答案 875. 爱吃香蕉的珂珂 #include <vector> #incl
9
0
0
二维前缀和与差分、离散化技巧
摘要:二维前缀和 304. 二维区域和检索 - 矩阵不可变 二位前缀和目的是预处理出一个结构,以后每次查询二维数组任何范围上的累加和都是 O(1) 的操作 根据原始状况,生成二维前缀和数组sum, sum[i][j]: 代表左上角 (0,0) 到右下角 (i,j) 这个范围的累加和 sum[i][j] +
28
0
0
双指针
摘要:双指针 同向指针 快慢指针 从两端向中间的指针 其他 922. 按奇偶排序数组 II #include <vector> using namespace std; class Solution { public: // 时间复杂度 O(n),额外空间复杂度 O(1) vector<int> sort
9
0
0
滑动窗口
摘要:滑动窗口 维持左右边界都不回退的一段范围,求解子数组、子串相关问题 求子数组以每个位置开头或者结尾情况下的答案 找范围和答案指标之间的单调性关系 209. 长度最小的子数组 #include <vector> #include <valarray> using namespace std; clas
5
0
0
根据数据量猜解法
摘要:根据数据量猜解法 常数指令操作量 10^7 ~ 10^8,以此来猜测自己设计的算法有没有可能在规定时间内通过 消灭怪物 全排列 #include <vector> #include <iostream> using namespace std; int res; vector<pair<int, i
8
0
0
N皇后问题
摘要:N皇后问题 时间复杂度为 O(n!) 51. N 皇后 经典做法 #include <string> #include <iostream> #include <vector> #include <unordered_set> using namespace std; class Solution
5
0
0
嵌套类递归
摘要:嵌套类递归 都需要一个全局变量记录当前正在处理的位置 基础计算器 III 含有嵌套的表达式求值,时间复杂度 O(n) #include <iostream> #include <string> #include <vector> using namespace std; class Solution
15
0
0
经典递归
摘要:master 公式 所有子问题规模相同的递归才能用master公式:T(n) = a * T(n / b) + O(n ^ c),a、b、c为常数 a 表示递归的次数也就是生成的子问题数,b 表示每次递归是原来的 1/b 之一个规模,O(n ^ c) 表示分解和合并所要花费的时间之和。 若 log(
8
0
0
构建前缀信息解决子数组问题
摘要:构建前缀信息解决子数组问题 303. 区域和检索 - 数组不可变 #include <vector> using namespace std; class NumArray { public: // 前缀和数组 vector<int> prefixSum; NumArray(vector<int>
4
0
0
二叉树高频题(下)
摘要:二叉树高频题(下) 236. 二叉树的最近公共祖先 using namespace std; struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(nullptr), ri
4
0
0
二叉树高频题(上)
摘要:二叉树高频题(上) 102. 二叉树的层序遍历 #include <vector> #include <iostream> #include <algorithm> #include <queue> using namespace std; struct TreeNode { int val; Tr
9
0
0
链表高频题
摘要:链表高频题 160. 相交链表 #include <vector> #include <iostream> #include <algorithm> struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(N
7
0
0
点击右上角即可分享
微信分享提示
深色
回顶
收起