package com.tjrac_java_2;
import java.util.Scanner;
public class Lcs {
public static void main(String[] args) {
String x,y;
int[][] sum= new int [505][505];
int i,j,len1,len2;
Scanner sc = new Scanner(System.in);
while(sc.hasNext())
{
x=sc.nextLine();
y=sc.nextLine();
len1=x.length();
len2=y.length();
for(i=1;i<=len1;i++)
{
for(j=1;j<=len2;j++)
{
if(x.charAt(i-1)==y.charAt(j-1))
sum[i][j]=sum[i-1][j-1]+1;
else
sum[i][j]=Math.max(sum[i-1][j],sum[i][j-1]);
}
}
System.out.println(sum[len1][len2]);
}
}
}
LCS最长公共子序列java实现代码保存
最新推荐文章于 2023-06-04 23:23:44 发布