Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <iostream>#include <cstring>using namespace std;const int MAXM = 2101;const int MAXN = 2101;int dp[MAXM][MAXN]; // max lengthint match[MAXM][MAXN]; // match lengthint m, n;string a, b;int get_max() {if (m < 3 || n < 3) {return 0;}memset(match, 0, sizeof(match));memset(dp, 0, sizeof(dp));for (int i = m-1; i >= 0; --i) {for (int j = n-1; j >= 0; --j) {dp[i][j] = max(dp[i+1][j], dp[i][j+1]);if (a[i] == b[j]) {match[i][j] = match[i+1][j+1] + 1;} else {match[i][j] = 0;}if (match[i][j] >= 3) {dp[i][j] = max(dp[i][j], dp[i+match[i][j]][j+match[i][j]] + match[i][j]);}