L2-4. 最长对称子串
注意连续子串
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cmath> #include <stack> #include <string> #include <queue> #include <vector> #include <map> #include <algorithm> const int inf = 0x3f3f3f; const int MAXN = 1e3+10; using namespace std; string ts1,ts2; int dp[2][MAXN]; int main() { while(getline(cin,ts1)){ // transform(ts1.begin(),ts1.end(),ts1.begin(),::tolower); int len = ts1.size(); ts2 = ts1; reverse(ts2.begin(),ts2.end()); // cout<<ts2<<endl; int mmax = 0; memset(dp,0,sizeof(dp)); for(int i=1;i<=len;i++){ for(int j=1;j<=len;j++){ if(ts1[i-1]==ts2[j-1]){ dp[i%2][j] = dp[(i-1)%2][j-1]+1; mmax = max(mmax,dp[i%2][j]); } else dp[i%2][j] = 0; } } cout<<mmax<<endl; } //cout << "Hello world!" << endl; return 0; }
连续lcs
时间: 2024-12-01 06:43:45