public class LCS
{
public static char[] s1 = {'a', 'b', 'c', 'b', 'd', 'a', 'b'};
public static char[] s2 = {'b', 'd', 'c', 'a', 'b', 'a'};
//public static int q;
public static int[][] c = new int[s1.length+1][s2.length+1];
public static void main(String[] args)
{
System.out.println(LCS_length(s1.length, s2.length));
}
public static int LCS_length(int m, int n)
{
for (int i = 1; i <= m; i++)
{
for (int j = 1; j <= n; j++)
{
if (s1[i-1] == s2[j-1])
{
c[i][j] = c[i-1][j-1] + 1;
}
else
{
c[i][j] = Math.max(c[i-1][j], c[i][j-1]);
}
}
}
return c[m][n];
}
}
LCS
最新推荐文章于 2025-03-19 17:55:16 发布