#include <iostream> using namespace std; int lps(string seq, int i, int j) { int len1, len2; if (i == j)//当i=j时,则此时扫描到的项是一定可以放入该回文子序列中并且对回文子序列的长度贡献为1 ; if (i > j)//当i>j时,即扫描到的左边的数在右边已经扫描过了,所以该项及往后的所有项都是已经扫描过的项,对回文子序列的长度贡献为0 ; if (seq[i] == seq…
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000. Example 1:Input: "bbbab" Output: 4 One possible longest palindromic subsequence is "bbbb". Example 2:Input:…
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000. Example 1:Input: "bbbab" Output: 4 One possible longest palindromic subsequence is "bbbb". Example 2:Input:…
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000. Example 1:Input: "bbbab" Output: 4 One possible longest palindromic subsequence is "bbbb". Example 2:Input:…