摘要:
class Solution { public: string largestMerge(string word1, string word2) { string ans; int i = 0, j = 0; while (i < word1.size() || j < word2.size()) 阅读全文
摘要:
简单的模拟 class Solution { public: int finalValueAfterOperations(vector<string>& operations) { int ans = 0; for (auto str : operations) { if (str[0] == 'X 阅读全文
摘要:
【LC1799】 class Solution { public: int n; vector<int> dp; //状态DP; vector<vector<int>> gcd; //gcd<i, j>:nums[i], nums[j] gcd的结果; int GCD(int x, int y) { 阅读全文
摘要:
Trie树 Trie树也叫字典树。 主要是用于多个字符串中与某个字符串的匹配,也是AC自动机的一个基础。 Trie树的好处在于匹配时只需要O(N)算法即可完成,如果使用暴力则需要O(MN),这就是一种优化。 Trie树的实现 一般是利用多个数组来模拟树的链接关系。 为了简单起见,我们只考虑小写字母的 阅读全文
摘要:
https://leetcode.cn/problems/implement-magic-dictionary/ static int son[10010][26]; int idx = 0; static int cnt[10010]; class MagicDictionary { public 阅读全文
摘要:
[LC2300] class Solution { public: using LL = long long; vector<int> successfulPairs(vector<int>& spells, vector<int>& potions, long long success) { // 阅读全文
摘要:
A*算法 A*算法是在图形平面中,对于有多个节点的路径求出最低通过成本的算法。其属于图遍历算法,算是对BFS算法基础上进行优化改进。其改进是在进行距离估计时,运用了启发式函数进行预估。 具体来说,对于通常的距离计算,假定起点为s,终点为t,从起点到点x的最短真实距离为g(x),x到终点的估计距离为h 阅读全文
摘要:
# Z函数及扩展KMP ## 1.0 Z函数定义及示例 首先Z函数是啥? 其定义为Z(i): 为s和s[i, n]的最长公共前缀(LCP)(这里假定字符序列都是从下标1开始,下文就不赘述)。 用更加形式一点的描述就是: Z(i) = max{x | s[1, x] = s[i, i + x -1]} 阅读全文
摘要:
你现在需要设计一个密码 S,S 需要满足: S 的长度是 N; S 只包含小写英文字母; S 不包含子串 T; 例如:abc 和 abcde 是 abcde 的子串,abd 不是 abcde 的子串。 请问共有多少种不同的密码满足要求? 由于答案会非常大,请输出答案模 109+7 的余数。 输入格式 阅读全文
摘要:
能量石这个问题,一方面是分析出贪心所得强性质。 另一方面是状态定义时,恰好和至多的区别。 当恰好时,最后求得结果需要遍历。 对于定义为至多时,因为后面价值无法保证在状态转移时保证,单点递增顺序。仍旧需要遍历一次得到结果。 是个很不错的综合题目。 【ACwing734】 岩石怪物杜达生活在魔法森林中, 阅读全文