明清经济史论文集pdf:懂c++的进啊,在线等。

来源:百度文库 编辑:高校问答 时间:2024/05/09 02:17:34
#include<iostream.h>
int LcsLength(char *x,char *y ,int **b,int m,int n)
{
int i,j;
int **c;
c=new int *[m+1];
for(i=1;i<=n+1;i++)
c[i]=new int[n+1];
for(i=1;i<m+1;i++)c[i][0]=0;
for(i=1;i<n+1;i++)c[0][i]=0;
for(i=1;i<=m+1;i++)
for(j=1;j<=n+1;j++)
{
if(x[i]=y[j])
{
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;

}
}
return c[m][n];
}
void Lcs(int i,int j,char *x,int **b)
{
if(i==0||j==0) return;
if(b[i][j]==1)
{
Lcs(i-1,j-1,x,b);
cout<<x[i];

}
else if(b[i][j]==2)
Lcs(i-1,j,x,b);
else //if(b[i][j]==3)
Lcs(i,j-1,x,b);
}
void main()
{int i, m,n;
char *x,*y;
int **b;
cout<<"请输入第一个窜的长度m"<<endl;
cin>>m;
cout<<"请输入第二个窜的长度n"<<endl;
cin>>n;
x=new char [m];
y=new char [n];
cout<<"请输入第一个窜"<<endl;
cin>>x+1;
cout<<"请输入第二个窜"<<endl;
cin>>y+1;
b=new int *[m+1];
for(i=1;i<=n+1;i++)
b[i]=new int[n+1];
cout<<"该公共子序列的长度为"<<endl;
cout<<LcsLength(x,y,b,m,n)<<endl;
cout<<"公共子序列为"<<endl;
Lcs(m,n,x,b);
cout<<endl;
delete []x;//[]y;[][]b,[][]c;

}
这个求公共子序列那里错了啊。