最长公共子序列java源程序代码.docVIP

  • 20
  • 0
  • 约3.73千字
  • 约 5页
  • 2016-11-08 发布于江苏
  • 举报
最长公共子序列java源程序代码.doc

以下为最长公共子序列问题的两种程序,分别通过两种算法实现: 方法一: public class LcsLength { public static int lcsLength(char []x,char []y,int [][]b) { int m=x.length; int n=y.length; int[][] c=new int[m+1][n+1]; for(int i=0;i=m;i++) c[i][0]=0; for(int i=0;i=n;i++) c[0][i]=0; for(int i=1;i=m;i++) for(int j=1;j=n;j++) { if(x[i-1]==y[j-1]) { c[i][j]=c[i-1][j-1]+1; b[i][j]=1; } else if(c[i-1][j]=c[i][j-1]) { c[i][j]=c[i-1][j]; b[i][j]=2; } else { c[i][j]=c[i][j-1]; b[i][j]=3; } } int i=m;int j=n; lcs(i,j,x,b

文档评论(0)

1亿VIP精品文档

相关文档