因为a需要作为一个字串,b作为一个子序列
所以b里的字母可以分散在字符串中
我们需要找到b里的字母在a中分散重合的最大数量,假设为res
(求法:枚举,枚举重合第一个字母的起点)
则最短的字符串长度就是a.size() + b.size() - res
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include "bits/stdc++.h"
using namespace std;
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fios ofstream("test.txt");cout.rdbuf(out.rdbuf())
#define endl "\n"
#define INF 0x3f3f3f3f
#define MINF 2147483647
#define eps 1e-6
#define PI acos(-1)
#define lowbit(x) (x & (-x))
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> PII;
#define x first
#define y second
const int N = 1010;
int f[N][N];
int main()
{
int T;
cin >> T;
while(T--)
{
memset(f, 0, sizeof f);
string a, b;
cin >> a >> b;
int n = a.size(), m = b.size();
a = " " + a;
b = " " + b;
int res = 0;
for(int i = 1; i <= m; i++)
{
int cnt = 0;
for(int j = 1; j <= n; j++)
{
if(b[i + cnt] == a[j])
{
cnt++;
res = max(res, cnt);
}
}
}
cout << n + m - res << endl;
}
return 0;
}