Problem Description You have a sequence {a1,a2,...,an} and you can delete a contiguous subsequence of length m. So what is the minimum number of inver ...
分类:
编程语言 时间:
2016-11-26 23:16:30
阅读次数:
271
Naive Solution: use DP, Time O(N^2), Space O(N) dp[i] represents the length of longest increasing subsequence till i including element i in nums array ...
分类:
其他好文 时间:
2016-11-23 08:13:25
阅读次数:
117
一个sequence,里面都是整数,求最长的subsequence的长度,使得这个subsquence的最大值和最小值相差不超过1. 比如[1,3,2,2,5,2,3,7]最长的subsequence是[3,2,2,2,3],所以应该返回5. 分析: 这题可以先排序,然后找出两个相差1的相邻值的最大 ...
分类:
其他好文 时间:
2016-11-22 02:41:37
阅读次数:
126
Given a sequence of n integers a1, a2, ..., an, a 132 pattern is a subsequence ai, aj, ak such that i < j < k and ai < ak < aj. Design an algorithm th ...
分类:
其他好文 时间:
2016-11-20 07:01:22
阅读次数:
251
Given a string S and a string T, count the number of distinct subsequences of T in S. (Hard) A subsequence of a string is a new string which is formed ...
分类:
其他好文 时间:
2016-11-17 23:44:23
阅读次数:
208
【题目链接】 http://poj.org/problem?id=3061 【题目大意】 给出S和一个长度为n的数列,问最短大于等于S的子区间的长度。 【题解】 利用双指针获取每一个恰好大于等于S的子区间,更新答案即可。 【代码】 ...
分类:
其他好文 时间:
2016-11-17 01:49:32
阅读次数:
135
http://poj.org/problem?id=1458 用dp[i][j]表示处理到第1个字符的第i个,第二个字符的第j个时的最长LCS。 1、如果str[i] == sub[j],那么LCS长度就可以+1,是从dp[i - 1][j - 1] + 1,因为是同时捂住这两个相同的字符,看看前面 ...
分类:
其他好文 时间:
2016-11-04 23:40:36
阅读次数:
254
注意最长公共子串(Longest CommonSubstring)和最长公共子序列(LongestCommon Subsequence, LCS)的区别:子串(Substring)是串的一个连续的部分,子序列(Subsequence)则是从不改变序列的顺序,而从序列中去掉任意的元素而获得的新序列;更 ...
分类:
其他好文 时间:
2016-11-04 14:24:17
阅读次数:
200
Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求LCS,转移同时维护f[i][j].s为当前状态字典序最小最优解 f[n][n].s的前半部分一定是回文串的前半部分(想想就行 ...
分类:
其他好文 时间:
2016-11-04 01:41:08
阅读次数:
166
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from t ...
分类:
编程语言 时间:
2016-11-02 07:26:55
阅读次数:
221