Sub d53_动态规划_最长回文子序列() text1 = "cbbdbbbbbdddddddddddd" res = longestPalindromeSubseq(text1) Debug.Print (res) End Sub Private Function longestPalindromeSubseq(s) leng = Len(s) ReDim dp(leng, leng) For i = leng - 1 To 1 Step -1 dp(i, i) = 1 For j = i + 1 To leng If Mid(s, i, 1) = Mid(s, j, 1) Then dp(i, j) = dp(i + 1, j - 1) + 2 Else dp(i, j) = Application.Max(dp(i + 1, j), Application.Max(dp(i, j), dp(i, j - 1))) End If Next Next longestPalindromeSubseq = dp(1, leng) End Function
标签:longestPalindromeSubseq,End,序列,leng,最长,dp,回文 From: https://www.cnblogs.com/eyunkeji/p/16965408.html