資源簡介
該算法程序可以計算兩個字符串包含的多個子序列和其長度,并同時輸出多個子序列
代碼片段和文件信息
#include
#include
#include
//#include
#include
using?namespace?std;
void?Print(int?iint?j);
string?str1str2;
int?t=0;//t表示分路數
int?L[100][100]={-1-1};int?M[100][100]={-1-1};
int?main()
{
//char?a[100]={-1};
cout<<“請輸入序列1“< cin>>str1;
cout<<“請輸入序列2“< cin>>str2;
int?n=str1.length();int?m=str2.length();int?s=0;
//vector?L;
//L.resize(n*m);
for(int?i=0;i {?L[i][0]=0;M[i][0]=0;}
for(int?j=0;j {??L[0][j]=0;M[0][j]=0;}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(str1.at(i-1)==str2.at(j-1))
{
L[i][j]=L[i-1][j-1]+1;
????????????????????M[i][j]=1;//表示L[i][j]的值來自于斜對角線
}
else
{
if(L[i][j-1]>L[i-1][j])
{
L[i][j]=L[i][j-1];
????M[i][j]=2;//表示L[i][j]的值來自于左邊
}
else?if(L[i][j-1] {
L[i][j]=L[i-1][j];
???? M[i][j]=3;//表示L[i][j]的值來自于上
- 上一篇:語音信號處理c程序
- 下一篇:Hough變換 C 語言實現
評論
共有 條評論