求最长公共子序列,题意就不再解释了,裸地、、、、、、、、、、
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <string>
using namespace std;
int s[250], t[250];
int LCS(string s1, string s2){
int len1 = s1.length();
int len2 = s2.length();
for(int i = 0; i <= len2; i++) t[i] = 0;
for(int i = 0; i < len1; i++){
for(int j = 0; j < len2; j++){
if(s1[i] == s2[j]) s[j+1] = t[j] + 1;
else s[j + 1] = s[j] > t[j + 1] ? s[j] : t[j + 1];
}
for(int j = 1; j <= len2; j++) t[j] = s[j];
}
return t[len2];
}
int main(){
#ifdef LOCAL
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif
string s1, s2;
while(cin>>s1>>s2){
int n = LCS(s1,s2);
cout<<n<<endl;
}
return 0;
}