LCString
约 105 字
预计阅读 1 分钟
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string a, b;
int dp[1001][1001], ans;
int main()
{
cin >> a >> b;
int lena = a.length(), lenb = b.length();
for(int i = 0;i < lena;i++)
{
for(int j = 0;j < lenb;j++)
{
if(a[i] == b[j])
{
if(i == 0 ||j == 0)
dp[i][j] = 1;
else
dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1);
ans = max(ans, dp[i][j]);
}
else
dp[i][j] = 0;
}
}
cout << ans << endl;
return 0;
}
/*Substring*/
|