Given two strings, a and , b find and print the total number of ways to insert a character at any position in string a such that the length of the Longest Common Subsequence of characters in the two strings increases by one. Input Format The first l…
先要搞明白:最长公共子串和最长公共子序列的区别. 最长公共子串(Longest Common Substirng):连续 最长公共子序列(Longest Common Subsequence,LCS):不必连续 实在是汗颜,网上做一道题半天没进展: 给定一个字符串s,你可以从中删除一些字符,使得剩下的串是一个回文串.如何删除才能使得回文串最长呢?输出需要删除的字符个数. 首先是自己大致上能明白应该用动态规划的思想否则算法复杂度必然过大.可是对于回文串很难找到其状态和状态转移方程,换句话…
a typical variant of LCS algo. the key point here is, the dp[][] array contains enough message to determine the LCS, not only the length, but all of LCS candidate, we can backtrack to find all of LCS. for backtrack, one criteria is dp[i-1][j]==dp[i][…