-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1506C_2.cpp
More file actions
50 lines (44 loc) · 1.08 KB
/
1506C_2.cpp
File metadata and controls
50 lines (44 loc) · 1.08 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// dp
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
inline void quick_IO() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
int main() {
quick_IO();
int t;
cin >> t;
while (t--) {
string a, b;
cin >> a >> b;
int a_size = (int) a.size();
int b_size = (int) b.size();
int dp[a_size + 1][b_size + 1];
int result = 0;
for (int i = 0; i <= b_size; ++i) {
dp[0][i] = 0;
}
for (int i = 0; i <= a_size; ++i) {
dp[i][0] = 0;
}
for (int i = 0; i <= a_size; ++i) {
for (int j = 0; j <= b_size; ++j) {
if(i==0||j==0){
dp[i][j] = 0;
}
else if (a[i-1] == b[j-1]) {
dp[i][j] = dp[i-1][j-1] + 1;
result = max(result, dp[i][j]);
} else {
dp[i][j] = 0;
}
}
}
cout << a_size+b_size-2*result<<"\n";
}
return 0;
}