10 2021 档案
摘要:1938. 查询最大基因差 离线 + \(Trie\) 建树后$dfs$,每访问一个节点 \(v\),就插入 \(Trie\) ,并回答v的所有询问,然后将 \(v\) 从 $Trie$中删去。 using PII = pair<int,int>; const int N = 1e5 + 10; i
阅读全文
摘要:638. 大礼包 完全背包 + 状压 + 记忆化搜索 class Solution { public: vector<vector<int>>special; vector<unordered_map<int, int>> f; vector<int>price; int n; int dp(int
阅读全文
摘要:5909. 并行课程 III DAG上的动态规划 板子题 const int N = 5e4 + 20; int h[N],ne[N * 2], e[N * 2],idx,res,q[N],hh,tt,n,d[N],ddl[N]; class Solution { public: void add(
阅读全文
摘要:5908. 统计最高分的节点数目 dfs using ll = long long; class Solution { public: ll n, res, ans; ll dfs(vector<vector<int>>& G, int root){ ll cnt = 1,tmp = 1; for(
阅读全文
摘要:5906. 句子中的有效单词数 暴力 class Solution { public: int countValidWords(string sentence) { int cnt = 0, n = sentence.size(); for(int i = 0; i < n; ++i){ if(se
阅读全文
摘要:5907. 下一个更大的数值平衡数 打表 + 二分 class Solution { public: vector<int>t; int nextBeautifulNumber(int n) { t = {0,1,22,122,212,221,333,1333,3133,3313,3331,4444
阅读全文
摘要:767. 重构字符串 法1:贪心,每次在$res$尾巴放剩余数目最多的字符,但要保证与当前尾巴字符不同,若相同则换次大字符,用堆维护。 using PIC = pair<int,char>; class Solution { public: string reorganizeString(strin
阅读全文
摘要:Jury Meeting 会有一个人连续说两个任务说明在某一轮中他是最后一个发言且除他之外的人都已经说完了所有任务,因此在下一轮中他成为了第一个发言的人。因此我们可以从所有人的任务数中的最大值的角度考虑这个问题。 如果最大值的数量不唯一,则这些任务数量最大的人一定是在同一轮说完所有任务的,不会出现不
阅读全文
摘要:135. 分发糖果 法一:记忆化搜索,找最长下降路径 class Solution { public: int dp(int x, vector<int>&ratings, vector<int>& f){ if(~f[x])return f[x]; int a = x - 1, b = x + 1
阅读全文
浙公网安备 33010602011771号