• 2024-06-21算法合集
    算法合集这里是我的算法合集:博弈论Gametheory图论Graphtheory数论Numbertheory三角函数Trigonometricfunction字符串Strings计算几何Computationgeometry数据结构Structs动态规划DynamicprogrammingLIS问题LongestIncreasingSubsequenceproble
  • 2024-06-21算法合集
    算法合集这里是我的算法合集:博弈论Gametheory图论Graphtheory数论Numbertheory三角函数Trigonometricfunction字符串Strings计算几何Computationgeometry数据结构Structs动态规划DynamicprogrammingLIS问题LongestIncreasingSubsequenceproble
  • 2024-05-21300-Longest Increasing Subsequnce-最长递增子序列
    问题描述链接:https://leetcode.com/problems/longest-increasing-subsequence/description/Givenanintegerarray nums,return thelengthofthelongest strictlyincreasing subsequence解释:给定一个数组nums,返回长的严格递增子序列。案例:Input:nums=[10,9,
  • 2024-05-205-Longest Palindromic Substring-最长回文串
    问题描述链接:https://leetcode.com/problems/longest-palindromic-substring/description/Givenastring s,return thelongest palindromicsubstringins解释:给定一个字符串,求其最长的回文串回文串:一个字符串,如果从左往右读和从左往右读读出来的序列是一样的,称
  • 2024-04-19Effective Python:第8条 用zip函数同时遍历两个迭代器
    用Python内置的zip函数来实现。这个函数能把两个或更多的iterator封装成惰性生成器(lazygenerator)。每次循环时,它会分别从这些迭代器里获取各自的下一个元素,并把这些值放在一个元组里面。names=["Cecilia","Lise","Marie"]counts=[len(n)forninnames]max_count=
  • 2023-12-24Longest Path
    每个点肯定是它上个点转移过来的#include<bits/stdc++.h>usingnamespacestd;constintN=1e5+10;vector<int>a[N];intd[N],dp[N];voidsolve(){ intn,m; cin>>n>>m; for(inti=1;i<=m;i++){ intu,v; cin>>u>>v; a[u].push_back(v
  • 2023-12-23『LeetCode』5. 最长回文子串 Longest Palindromic Substring
    题目描述给你一个字符串s,找到s中最长的回文子串。如果字符串的反序与原始字符串相同,则该字符串称为回文字符串。示例1:输入:s="babad"输出:"bab"解释:"aba"同样是符合题意的答案。示例2:输入**:s="cbbd"输出:"bb"提示:1<=s.length<=1000s仅由数字和英文字母组
  • 2023-12-22『LeetCode』3. 无重复字符的最长子串 Longest Substring Without Repeating Characters
    『1』双指针算法我的想法:一般看到字符串子串问题想到用双指针解,看到字符串子序列问题想到用动态规划解。此题用双指针可以很快解题。遍历字符串中的每个字符s.charAt[i],对于每一个i,找到j使得双指针[j,i]维护的是以s.charAt[i]结尾的无重复字符的最长子串,长度为i-j+1,
  • 2023-08-28[LeetCode][300]longest-increasing-subsequence
    ContentGivenanintegerarraynums,returnthelengthofthelongeststrictlyincreasingsubsequence. Example1:Input:nums=[10,9,2,5,3,7,101,18]Output:4Explanation:Thelongestincreasingsubsequenceis[2,3,7,101],thereforethelengthis4.E
  • 2023-08-18[LeetCode][32]longest-valid-parentheses
    ContentGivenastringcontainingjustthecharacters'('and')',returnthelengthofthelongestvalid(well-formed)parenthesessubstring. Example1:Input:s="(()"Output:2Explanation:Thelongestvalidparentheses
  • 2023-08-18LeetCode[32]LongestValidParentheses
    ContentGivenastringcontainingjustthecharacters'('and')',returnthelengthofthelongestvalid(well-formed)parenthesessubstring. Example1:Input:s="(()"Output:2Explanation:Thelongestvalidparentheses
  • 2023-08-17[32]Longest Valid Parentheses
    ContentGivenastringcontainingjustthecharacters'('and')',returnthelengthofthelongestvalid(well-formed)parenthesessubstring. Example1:Input:s="(()"Output:2Explanation:Thelongestvalidparentheses
  • 2023-08-14Codechef - Longest AND Subarray(位运算)
    题目大意  给定一个正整数N,其序列为[1,2,3,...,N],找到一个长度最大的连续子列,使得其所有元素取与运算的结果为正(最终输出只需要输出最大长度即可)。 思路  刚开始可能并不好注意到,可以举一些小的样例来找规律。比如2:1&2=0,不满足条件,所以只能取长度为1的数组[1]或
  • 2023-08-08B. Longest Divisors Interval
    link需要思考一下如果这个题能做,那么肯定有一种比较可行的做法。如果\([l,r]\)是可行的,那么就意味着\([1,r-l+1]\)是可行的这是显然的,显然后者的每一个数在前者中必然有对应的倍数,所以等效。这样从1开始找就行了。#include<cstdio>#include<iostream>#include<cstring>#i
  • 2023-08-03Codeforces 1855B:Longest Divisors Interval 最长的连续约数区间
    1855B.LongestDivisorsIntervalDescription:对于一个整数\(n\)\((1\leqn\leq10^{18})\),找到一段最长的区间\([l,r]\),使得区间内所有数均为\(n\)的约数。Analysis:如果\(n\)是一个奇数(非\(2\)的倍数),由于\(odd=odd\timesodd\),则不可能有连续的两个整数均为
  • 2023-07-31Longest Divisors Interval
    Smiling&Weeping----总有一个人,一直住在心底,却消失在生活里。Givenapositiveintegern,findthemaximumsizeofaninterval[l,
  • 2023-06-15Longest Path (牛客多校) (换根DP+斜率优化)
    换根dp:第一次dfs处理儿子点的权值第二次dfs处理父亲点,和兄弟节点的权值处理兄弟节点的时候,利用父亲节点统一处理,利用stl存储斜率优化:为什么会用到斜率优化:在遇到转移式子是fixfj的时候,不是分开的,(分开的,直接用单调队列处理)(通常会遇到平方式子)把
  • 2023-06-09Leetcode Hot 100 & 128. Longest Consecutive Sequence
    参考资料:考点:哈希&[题干]Input:nums=[100,4,200,1,3,2]Output:4Explanation:Thelongestconsecutiveelementssequenceis[1,2,3,4].Thereforeitslengthis4.做的时候冥思苦想了半天,因为这个题目要求是O(n)的解法,后来看到题解的时候还一度怀
  • 2023-05-30leetcode 594. Longest Harmonious Subsequence
    Wedefineaharmoniousarrayisanarraywherethedifferencebetweenitsmaximumvalueanditsminimumvalueisexactly1.Now,givenanintegerarray,youneedtofindthelengthofitslongestharmonioussubsequenceamongallitspossiblesubsequences.E
  • 2023-05-26128. Longest Consecutive Sequence刷题笔记
    取巧用了python自带的排序算法,该算法为Timsort,复杂度为nlog(n)classSolution:deflongestConsecutive(self,nums:List[int])->int:ifnotnums:return0nums.sort()res=0length=1foriinrange(len(nu
  • 2023-03-115.最长回文子串
    最长回文子串给你一个字符串s,找到s中最长的回文子串。如果字符串的反序与原始字符串相同,则该字符串称为回文字符串。示例1:输入:s="babad"输出:"bab"解释:"aba"
  • 2023-02-27G - Longest Path -- 拓扑序 + DP
    G-LongestPathhttps://atcoder.jp/contests/dp/tasks/dp_g 思路使用拓扑序,依此从入度为0的节点开始,向外扩展,直至只剩一个节点扩展的过程中,对每个点的最大路径做
  • 2023-02-20LeetCode OJ Longest Substring Without Repeating Characters 不重复的最长字串 滑动窗口
    LongestSubstringWithoutRepeatingCharactersGivenastring,findthelengthofthelongestsubstringwithoutrepeatingcharacters.Forexample,thelongest
  • 2023-02-20[ARC156C] Tree and LCS
    ProblemStatementWehaveatree$T$withverticesnumbered$1$to$N$.The$i$-thedgeof$T$connectsvertex$u_i$andvertex$v_i$.Letususe$T$todefine
  • 2023-02-08Codeforces Round #722 (Div. 2)B. Sifid and Strange Subsequen
    problemB.SifidandStrangeSubsequencestimelimitpertest1secondmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputAsequence(b1