简体   繁体   English

如何找到最长的连续子序列,其反向也是子序列

[英]How to find the longest continuous subsequence whose reverse is also a subsequence

Suppose I have a sequence x1,x2,x3.....xn, and I want to find the longest continuous subsequence xi,xi+1,xi+2......xi+k, whose reverse is also a subsequence of the given sequence. 假设我有一个序列x1,x2,x3 ..... xn,我想找到最长的连续子序列xi,xi + 1,xi + 2 ... xi + k,其反向也是给定序列的子序列。 And if there are multiple such subsequences, then I also have to find the smallest i. 如果有多个这样的子序列,那么我也必须找到最小的i。

ex:- consider the sequences: 例如:-考虑以下顺序:

abcdefgedcg here i=3 and k=2 abcdefgedcg这里i = 3和k = 2

aabcdddd here i=5, k=3 aabcdddd这里i = 5,k = 3

I tried looking at the original longest common subsequence problem, but that is used to compare the two sequences to find the longest common subsequence.... but here is only one sequence from which we have to find the subsequences. 我尝试查看原始的最长公共子序列问题,但这是用来比较两个序列以找到最长公共子序列的问题。。。。但是这里只有一个序列,我们必须从中找到子序列。 Please let me know what is the best way to approach this problem, to find the optimal solution. 请让我知道解决此问题的最佳方法,以找到最佳解决方案。

Actually this is the longest common sub string problem applied to the sequence and its reverse: http://en.wikipedia.org/wiki/Longest_common_substring_problem 实际上,这是应用于序列及其反向序列的最长的公共子字符串问题: http : //en.wikipedia.org/wiki/Longest_common_substring_problem

This is distinct from longest common sub sequence : http://en.wikipedia.org/wiki/Subsequence#Substring_vs._subsequence 这与最长的公共子序列不同http : //en.wikipedia.org/wiki/Subsequence#Substring_vs._subsequence

apply longest common substring to the string and its reverse. 将最长的公共子字符串应用于字符串及其反向。

 LCS ("abcdefgedcg", "gcdegfedcba") = "cde"

EDIT : not subsequence as potatoswatter points out, not subsequence. 编辑 :不是potatoswatter指出的子序列,不是子序列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM