"Longest Subarray" 题意:一个数列,每个元素大小都在1到C之间,求一个最长的子串,满足在这个子串中1到C之间的每个数字要么出现0次,要么出现至少K次。 题解:$i$从1到n枚举右端点,维护一个$tree[j]$表示在$i$为右端点时以$j$为左端点可行的个数(这里的可行是指对于1到 ...
分类:
其他好文 时间:
2019-09-11 00:01:04
阅读次数:
105
Leetcode之动态规划(DP)专题-647. 回文子串(Palindromic Substrings) 给定一个字符串,你的任务是计算这个字符串中有多少个回文子串。 具有不同开始位置或结束位置的子串,即使是由相同的字符组成,也会被计为是不同的子串。 示例 1: 示例 2: 注意: dp: 定义: ...
分类:
其他好文 时间:
2019-09-10 09:14:02
阅读次数:
105
原题链接在这里:https://leetcode.com/problems/longest-turbulent-subarray/ 题目: A subarray A[i], A[i+1], ..., A[j] of A is said to be turbulent if and only if: ...
分类:
其他好文 时间:
2019-09-08 09:45:15
阅读次数:
68
Luogu P1470 最长前缀 Longest Prefix "Portal(传送门)" 注释 这道题与 "上一篇博客" 的题几乎一样 解析 + 有点麻烦的地方就是字符串的输入 方法一:类dp Code cpp include include include include include def ...
分类:
其他好文 时间:
2019-09-06 15:52:49
阅读次数:
81
dp问题,一维是没法dp的,因为我们还要记录一个diff才能判断是否是Arithmetic Sequence。 dp[i][diff] 表示以 A[i] 结尾,等差为 diff 的最大长度。从这种角度来看本题和 LeetCode 300. Longest Increasing Subsequence ...
分类:
其他好文 时间:
2019-09-04 10:25:10
阅读次数:
112
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path betwe ...
分类:
其他好文 时间:
2019-09-04 00:01:38
阅读次数:
129
一、LCS定义 ? 最长公共子序列(Longest Common Subsequence)? 一个序列S任意删除若干个字符得到的新序列T,则T叫做S的子序列? 两个序列X和Y的公共子序列中,长度最长的那个,定义为X和Y的最长公共子序列 – 字符串12455与245576的最长公共子序列为2455 – ...
分类:
其他好文 时间:
2019-09-03 16:13:54
阅读次数:
167
原题链接在这里:https://leetcode.com/problems/longest-common-subsequence/ 题目: Given two strings text1 and text2, return the length of their longest common sub ...
分类:
其他好文 时间:
2019-09-03 09:32:48
阅读次数:
62
题意: 输入两个正整数N和K(N<=1e10,k<=100),求K次内N和N的反置相加能否得到一个回文数,输出这个数和最小的操作次数。 trick: 1e10的数字相加100次可能达到1e40,所以long long会爆,采用字符数组操作,以及代码注释中遇到的一些小问题。 代码: #define H ...
分类:
其他好文 时间:
2019-09-01 18:58:49
阅读次数:
97
1040 Longest Symmetric String (25 分) 1040 Longest Symmetric String (25 分) 1040 Longest Symmetric String (25 分) Given a string, you are supposed to out ...
分类:
其他好文 时间:
2019-08-31 10:29:26
阅读次数:
72