简体   繁体   English

超过 2 个字符串的最长公共子序列

[英]Longest Common Subsequence for more than 2 strings

How to find the LCS (Longest Common Subsequence) for more than two strings?如何找到两个以上字符串的LCS (最长公共子序列)? We can solve for the LCS for two strings with DP, but how to proceed for LCS for more than two strings?我们可以用 DP 解决两个字符串的 LCS,但是对于两个以上的字符串如何进行 LCS?

I'm not sure if that's the best answer, but I guess a DP approach could work here as well.我不确定这是否是最好的答案,但我想 DP 方法也可以在这里工作。 With 2 strings you make a 2D array and fill it with "match lengths" for different starting/ending indeces of both strings (depending on your approach).使用 2 个字符串,您可以创建一个 2D 数组,并为两个字符串的不同起始/结束索引填充“匹配长度”(取决于您的方法)。 You could just use ND array for N strings, and fill it in the same way.您可以只对 N 个字符串使用 ND 数组,并以相同的方式填充它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM