基本思想:
总结过,不赘述;
关键点:
无;
#include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; const int maxn = 110; int dp[maxn][maxn]; string a, b; int main() { while (cin >> a >> b) { int lena = a.size() + 1; int lenb = b.size() + 1; for (int i = 0; i < lena; i++) { dp[i][0] = dp[0][i] = 0; } for (int i = 1; i < lena; i++) { for (int j = 1; j < lenb; j++) { if (a[i-1] == b[j-1]) { dp[i][j] = dp[i - 1][j - 1] + 1; } else { dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]); } } } cout << dp[lena-1][lenb-1] << endl; } return 0; }
上海交通大学机试 Coincidence 需要二刷 *最长公共子串典型问题
原文:https://www.cnblogs.com/songlinxuan/p/12618761.html