随笔分类 - 算法
摘要:std_list 的排序算法源码 源码 void sort() { // 如果链表为空,或者只有一个元素,则不需要排序,直接返回 if (node->next == node || link_type(node->next)->next == node) return; list carry; //
阅读全文
摘要:贪心6 1921. 消灭怪物的最大数量 #include <cstdio> #include <iostream> #include <vector> #include <algorithm> using namespace std; class Solution { public: int eli
阅读全文
摘要:贪心5 45. 跳跃游戏 II #include <vector> #include <algorithm> using namespace std; class Solution { public: int jump(vector<int> &nums) { int n = nums.size()
阅读全文
摘要:贪心4 1675. 数组的最小偏移量 #include <iostream> #include <vector> #include <set> using namespace std; class Solution { public: // 返回数组执行某些操作后可以拥有的最小偏移量 int min
阅读全文
摘要:贪心3 581. 最短无序连续子数组 #include <vector> #include <algorithm> #include <limits> using namespace std; class Solution { public: static int findUnsortedSubar
阅读全文
摘要:贪心2 LCR 132. 砍竹子 II #include <iostream> using namespace std; class Solution { public: const int MOD = 1e9 + 7; // 快速幂算法,计算 (x^n) % mod long long power
阅读全文
摘要:贪心1 179. 最大数 #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; class Solution { public: // 暴力方法生成所有可能的
阅读全文
摘要:动态规划中根据数据量猜解法 打怪兽 a[i] 范围大,b[i] 范围小的适用版本 #include <iostream> #include <vector> #include <climits> #include <algorithm> using namespace std; // 方法1:a[i
阅读全文
摘要:动态规划中得到具体决策方案 最长公共子序列 #include <iostream> #include <vector> #include <string> using namespace std; // 最大字符串长度 const int MAXN = 5001; // dp[i][j] 表示 s1
阅读全文
摘要:动态规划中优化枚举 1235. 规划兼职工作 #include <iostream> #include <vector> #include <algorithm> using namespace std; class Solution { public: int jobScheduling(vect
阅读全文
摘要:动态规划中优化枚举 121. 买卖股票的最佳时机 #include <iostream> #include <vector> using namespace std; class Solution { public: int maxProfit(vector<int> &prices) { int
阅读全文
摘要:数位DP(下) P2657 [SCOI2009] windy 数 #include <iostream> #include <vector> using namespace std; vector<vector<vector<int>>> dp; // 剩下 len 位没有确定 // 上一位数字为
阅读全文
摘要:数位DP(上) 357. 统计各位数字都不同的数字个数 using namespace std; class Solution { public: int countNumbersWithUniqueDigits(int n) { if (n == 0) return 1; int res = 10
阅读全文
摘要:状压DP(下) 1434. 每个人戴不同帽子的方案数 #include <iostream> #include <vector> #include <algorithm> using namespace std; class Solution { public: int MOD = 1e9 + 7;
阅读全文
摘要:状压DP(上) 464. 我能赢吗 #include <iostream> #include <vector> using namespace std; class Solution { public: bool canIWin(int n, int m) { if (m == 0) return
阅读全文
摘要:树型DP(下) 2477. 到达首都的最少油耗 #include <iostream> #include <vector> #include <algorithm> using namespace std; class Solution { public: int MAXN = 100001; //
阅读全文
摘要:树型DP(上) 最大BST子树 #include <iostream> #include <vector> #include <algorithm> #include <climits> using namespace std; class TreeNode { public: int val; T
阅读全文
摘要:区间DP 括号区间匹配 记忆化搜索 #include <iostream> #include <vector> #include <algorithm> using namespace std; int recursion(vector<char> &s, int l, int r, vector<
阅读全文
摘要:区间DP 1312. 让字符串成为回文串的最少插入次数 基于两侧端点讨论的可能性展开 暴力递归 #include <iostream> #include <vector> using namespace std; class Solution { public: int minInsertions(
阅读全文
摘要:title: 多重背包、混合背包 date: 2024-10-21 01:02:21 +0800 categories: [algorithm, problems] tags: [Algorithm, Knapsack problem, Monotonic Queue] description: 多
阅读全文