|
#include<iostream.h>
void LcsLength(int m,int n,char x[],char y[],int c[8][7],char b[8][7]);
void Lcs(int i,int j,char * x,char b[8][7]);
int main()
{
char x[]={'a','b','c','b','d','a','b'};
char y[]={'b','d','c','a','b','a'};
int xl=7;
int yl=6;
int c[8][7]={0};
char b[8][7]={0};
LcsLength(xl,yl,x,y,c,b);
Lcs(xl,yl,x,b);
return 0;
}
void LcsLength(int m,int n,char x[],char y[],int c[][],char b[][])
{
for(int i=1;i<=m;i++)int c[i][0]=0;
for(int j=1;j<=n;j++)c[0][j]=0;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
if(x[i]==y[j])
{
c[i][j]=c[i-1][j-1]+1;
b[i][j]='x';//xie xiang shang
}
else if(c[i-1][j]>=c[i][j-1])
{
c[i][j]=c[i-1][j];
b[i][j]='u';//up
}
else
{
c[i][j]=c[i][j-1];
b[i][j]='l';//left
}
}
}
void Lcs(int i,int j,char * x,char b[8][7])
{
if(i==0 ||j==0)
cout<<"Null"<<endl;
if(b[i][j]=='x')
{
Lcs(i-1,j-1,x,b);
cout<<x[i];
}
else if(b[i][j]=='u')Lcs(i-1,j,x,b);
else Lcs(i,j=1,x,b);
}
还是参数的问题,大家帮忙看下啊 |
|