Given a sequence, find the length of the longest palindromic subsequence in it. For example, if the given sequence is “BBABCBCAB”, then the output should be 7 as “BABCBAB” is the longest palindromic subseuqnce in it.“BBBBB” and “BBCBB” are also palindromic subsequences of the given sequence, but not the longest ones.
The naive solution for this problem is to generate all subsequences of the given sequence and find the longest palindromic subsequence. This solution is exponential in term of time complexity. Let us see how this problem possesses both important properties of a Dynamic Programming (DP) Problem and can efficiently solved using Dynamic Programming.
本文介绍了一种求解最长回文子序列的有效算法,并通过动态规划方法实现了该算法。通过对给定序列生成所有可能的子序列并找到最长的回文子序列,文章详细解释了算法的工作原理和实现细节。
254

被折叠的 条评论
为什么被折叠?



