Longest

P6922 [ICPC2016 WF] Longest Rivers 题解

Description 有 \(n\) 条河和 \(m+1\) 个交汇处构成一棵以 \(0\) 号点(即大海) 为根的树。 每条河有各自的名称。对于一个交汇处,从它流出的干流的名称是流入这个交汇处的各个支流的名称之一。一条河流的长度是以它为名称的河流的长度之和。对于一个可能的命名方案,一条河流的排名 ......
题解 Longest Rivers P6922 6922

Longest Path

每个点肯定是它上个点转移过来的 #include<bits/stdc++.h> using namespace std; const int N=1e5+10; vector<int>a[N]; int d[N],dp[N]; void solve(){ int n,m; cin>>n>>m; fo ......
Longest Path

『LeetCode』5. 最长回文子串 Longest Palindromic Substring

题目描述 给你一个字符串s,找到s中最长的回文子串。 如果字符串的反序与原始字符串相同,则该字符串称为回文字符串。 示例 1: 输入:s = "babad" 输出:"bab" 解释:"aba" 同样是符合题意的答案。 示例 2: 输入**:s = "cbbd" 输出:"bb" 提示: 1 <= s. ......

『LeetCode』3. 无重复字符的最长子串 Longest Substring Without Repeating Characters

『1』双指针算法 我的想法: 一般看到字符串子串问题想到用双指针解,看到字符串子序列问题想到用动态规划解。此题用双指针可以很快解题。 遍历字符串中的每个字符s.charAt[i], 对于每一个i,找到j使得双指针[j, i]维护的是以s.charAt[i]结尾的无重复字符的最长子串,长度为i - j ......

[LeetCode] 2609. Find the Longest Balanced Substring of a Binary String

You are given a binary string s consisting only of zeroes and ones. A substring of s is considered balanced if all zeroes are before ones and the numb ......
Substring LeetCode Balanced Longest Binary

SP10570 LONGCS - Longest Common Substring

SP10570 LONGCS - Longest Common Substring 更好的阅读体验 提供一个后缀数组解法。 多字符串,中间加分隔符然后后缀排序求出 \(sa\) 和 \(height\)。把每个字符串对应的位置染上颜色,问题变为寻找 \(i,j\) 使得区间 \([i,j]\) 包含 ......
Substring Longest LONGCS Common 10570

CF568E Longest Increasing Subsequence 题解

Longest Increasing Subsequence LIS 问题有两种主流 \(O(n\log n)\) 解法,最常见的树状数组法,以及不那么常见的二分法。然后考虑本题,发现一个神奇的思路就是求出 LIS 后倒序复原出数组。 进一步思考后发现,因为本题是 LIS(Longest Incre ......
题解 Subsequence Increasing Longest 568E

[CF568E] Longest Increasing Subsequence

题目描述 Note that the memory limit in this problem is less than usual. Let's consider an array consisting of positive integers, some positions of which c ......
Subsequence Increasing Longest 568E 568

* Codeforces Round 889 (Div. 2) B. Longest Divisors Interval

给一个正整数 $n$ ,找一段最长的 $[l, r]$ ,满足 $\forall i, i \in [l, r],\ s.t.\ i | n$ 。输出这一段区间的长度,即 $r - l + 1$ 。 这题是一个准结论题,需要一些知识点和观察的基础。 放在 $900$ 的位置是因为结论存在的区间太容易 ......
Codeforces Divisors Interval Longest Round

Python itertools.zip_longest(*iterables, fillvalue=None)

创建一个迭代器,从每个可迭代对象中收集元素。如果可迭代对象的长度未对齐,将根据 fillvalue 填充缺失值。 from itertools import zip_longest class Solution: def mergeAlternately(self, word1: str, word ......

[LeetCode][300]longest-increasing-subsequence

# Content Given an integer array nums, return the length of the longest strictly increasing subsequence. Example 1: Input: nums = [10,9,2,5,3,7,101,18 ......

Longest Common Prefix

> https://leetcode.cn/problems/longest-common-prefix/description/ > What's the "sort"? > A kind of overresearched cheating methods > Loosely speaking, ......
Longest Common Prefix

[LeetCode][32]longest-valid-parentheses

# Content Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses substring. Examp ......

[32]Longest Valid Parentheses

# Content Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses substring. Examp ......
Parentheses Longest Valid 32

Codechef - Longest AND Subarray(位运算)

题目大意 给定一个正整数N,其序列为[1, 2, 3, ..., N],找到一个长度最大的连续子列,使得其所有元素取与运算的结果为正(最终输出只需要输出最大长度即可)。 思路 刚开始可能并不好注意到,可以举一些小的样例来找规律。比如2:1 & 2 = 0,不满足条件,所以只能取长度为1的数组[1]或 ......
Codechef Subarray Longest AND

B. Longest Divisors Interval

[link](https://codeforces.com/contest/1855/problem/B) 需要思考一下 如果这个题能做,那么肯定有一种比较可行的做法。 如果$[l,r]$是可行的,那么就意味着$[1,r-l+1]$是可行的 这是显然的,显然后者的每一个数在前者中必然有对应的倍数,所 ......
Divisors Interval Longest

Codeforces 1855B:Longest Divisors Interval 最长的连续约数区间

# [1855B.Longest Divisors Interval](https://codeforces.com/contest/1855/problem/B "Codeforces 1855B") ## Description: - 对于一个整数 $n$ $(1\leq n \leq 10^{ ......
约数 区间 Codeforces Divisors Interval

Longest Divisors Interval

Smiling & Weeping 总有一个人, 一直住在心底, 却消失在生活里。 Given a positive integer n, find the maximum size of an interval [l,r] of positive integers such that, for e ......
Divisors Interval Longest

CF1855B Longest Divisors Interval 题解

原题链接:https://codeforces.com/contest/1855/problem/B 题意:给定一个正整数 n, 找到满足该条件的区间 [l, r] 的长度的最大值:对于任意 l <= i <= r,n 均为 i 的倍数(多组数据)。 思路:如果 n 是奇数,答案显然是 1,因为任意 ......
题解 Divisors Interval Longest 1855B

CF1855B Longest Divisors Interval 题解

## 题意: 给定一个数 $n$,求一个连续区间 $[l,r]$ 使得 $n$ 是区间内每个数的倍数,最大化这个区间的长度(多组数据)。 ## 思路: 逆向思考一波,( 如果一个数 $x$ 不是 $n$ 的因数,那么 $x$ 的倍数不能在区间内。 举个例子,比如 $ n $ 是13,3不是13的因数 ......
题解 Divisors Interval Longest 1855B

1124.longest well performing interval

Description 1124. Longest Well-Performing Interval (Medium) We are given hours, a list of the number of hours worked per day for a given employee. A d ......
performing interval longest 1124 well

1156. Swap For Longest Repeated Character Substring (Medium)

Description 1156. Swap For Longest Repeated Character Substring (Medium) You are given a string text. You can swap two of the characters in the text. ......
Character Substring Repeated Longest Medium

LeetCode 3. Longest Substring Without Repeating Characters 滑动窗口

Given a string `s`, find the length of the longest substring without repeating characters. ## Solution 用一个 $dict$ 来映射字符的次数。然后用 $left$, $right$ 来决定wind ......

[LeetCode] 1218. Longest Arithmetic Subsequence of Given Difference

Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that th ......

[LeetCode] 1493. Longest Subarray of 1's After Deleting One Element

Given a binary array nums, you should delete one element from it. Return the size of the longest non-empty subarray containing only 1's in the resulti ......
LeetCode Deleting Subarray Element Longest

Longest Path (牛客多校) (换根DP+斜率优化)

换根dp: 第一次dfs 处理儿子点的权值 第二次dfs 处理 父亲点,和兄弟节点的权值 处理兄弟节点的时候, 利用父亲节点统一处理, 利用stl存储 斜率优化: 为什么会用到斜率优化: 在遇到转移式子是 fi x fj 的时候, 不是分开的, (分开的,直接用单调队列处理) (通常会遇到平方式子) ......
斜率 Longest Path DP

Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string ```""```. ......
Longest Common Prefix

Leetcode Hot 100 & 128. Longest Consecutive Sequence

参考资料: 考点:哈希 & [题干] Input: nums = [100,4,200,1,3,2] Output: 4 Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its len ......
Consecutive Leetcode Sequence Longest Hot

[LeetCode] 1372. Longest ZigZag Path in a Binary Tree

You are given the root of a binary tree. A ZigZag path for a binary tree is defined as follow: Choose any node in the binary tree and a direction (rig ......
LeetCode Longest Binary ZigZag 1372

[Algorithm] Dynamic programming - 02 - Longest Common Subsequence - Drawing 2d matrix + back tracing

Write a function that takes in two strings and returns their longest common subsequence. A subsequence of a string is a set of characters that aren't ......
共30篇  :1/1页 首页上一页1下一页尾页