最长公共子序列

最长公共子序列 与 最长公共连续子串

 

//最长公共子序列(个数)
#include<iostream>
using namespace std;
int c[100][100]={0};
int len1,len2;
int  gcd(string a,string b){
    len1=a.length(); 
    len2=b.length();
    int tmp=-1;
    for(int i=0;i<len1;i++)
    {
        for(int j=0;j<len2;j++){
            if(a[i]==a[j]) c[i][j]=c[i-1][j-1]+1;
            else c[i][j]=max(c[i-1][j],c[i][j-1]);
            if(tmp<c[i][j]) tmp=c[i][j];
        }
    }
    return tmp;
}

int main()
{
    string a,b;
    while(cin>>a>>b){
    cout<<gcd(a,b);    
    }
} 
View Code

相关文章:

  • 2021-11-07
  • 2021-07-29
  • 2021-09-03
  • 2022-01-19
  • 2021-05-24
  • 2021-06-16
  • 2022-12-23
  • 2022-01-16
猜你喜欢
  • 2021-11-20
  • 2021-08-06
  • 2021-04-20
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案