关键字:最长公共子序列
题目描述
Find a longest common subsequence of two strings.
输入描述:
First and second line of each input case contain two strings of lowercase character a…z. There are no spaces before, inside or after the strings. Lengths of strings do not exceed 100.
输出描述:
For each case, output k – the length of a longest common subsequence in one line.
示例1
输入
abcd
cxbydz
输出
2
思路:
状态设计:dp[i][j] 为s1前i,s2前j个时最长的公共子序列
状态转移方程:
if(s1[i] == s2[j]) dp[i][j] = dp[i - 1][j - 1] + 1;
else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
代码:</

该博客主要介绍了如何寻找两个字符串的最长公共子序列问题,给出了一种基于动态规划的解决方案。博主分享了具体的思路,包括状态设计和状态转移方程,并通过一个实例展示了错误代码及其原因。
最低0.47元/天 解锁文章
1852

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



