题目大意:给定两个字符串,求其最大的公共子串。在这里子串的定义是:Given a sequence X = < x1, x2, ..., xm > ,another sequence Z = < z1, z2, ..., zk > is a subsequence of X if there exists a strictly increasing sequence < i1, i2, ..., ik > of indices of X such that for all j = 1,2,...,k, xij = zj. For example, Z = < a, b, f, c > is a subsequence of X = < a, b, c, f, b, c > with index sequence < 1, 2, 4, 6 >.
分析:简单DP
if(first[i]=second[j]) //在最大公共子串中,first[i]和second[j]恰好配对
count[i][j]=count[i-1][j-1]+1;
else count[i][j]=max(count[i-1][j],count[i][j-1]); //否则
最大公共子串求解

本文介绍了一种使用动态规划解决最大公共子串问题的方法。通过对比两个字符串的字符,递推地找出最长的共同子串。代码实现简洁,易于理解。
678

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



