-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumberString
57 lines (49 loc) · 1.09 KB
/
NumberString
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
51
52
53
54
55
56
57
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define pop pop_back
#define pr pair<ll,ll>
#define fi first
#define sec second
#define CASE(t) int t;cin>>t;while(t--)
typedef long long int ll;
int coun=0;
int lcs(ll dp[101][101],string a, string b, ll m, ll n)
{
if(m<0||n<0)
{
return 0;
}
if(dp[m][n]!=-1)
return dp[m][n];
ll ans=0;
if(a[m]==b[n])
{
ans=int(a[m]-48)+lcs(dp,a,b,m-1,n-1);
}
else
ans=max(lcs( dp,a, b,m-1,n),lcs(dp, a, b,m,n-1));
dp[m][n]=ans;
return ans;
}
int main()
{
CASE(t)
{
string a,b;
cin>>a>>b;
ll dp[101][101]={0};
for(int i=0;i<100;i++)
for(int j=0;j<100;j++)
dp[i][j]=-1;
int sum=0,res=0;
for(int i=0;i<a.size();i++)
sum+=int(a[i]-48);
for(int j=0;j<b.size();j++)
res+=int(b[j]-48);
int ans=sum+res-2*lcs(dp,a,b,a.length()-1,b.length()-1);
cout<<ans<<endl;
}
return 0;
}