Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- created: 2022-08-05-12.42.30
- ***/
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
- #define ll long long
- #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
- #define get_lost_idiot return 0
- #define nl '\n'
- string a,b;
- ll dp[62][62][62][62];
- ll solve(ll i,ll j,ll i1,ll j1)
- {
- if(i>j || i1>j1) return 0;
- if(dp[i][j][i1][j1]!=-1) return dp[i][j][i1][j1];
- ll ans=0;
- if(a[i]==a[j] && a[j]==b[i1] && b[i1]==b[j1])
- {
- if(i==j || i1==j1) ans=1 + solve(i+1,j-1,i1+1,j1-1);
- else ans= 2 + solve(i+1,j-1,i1+1,j1-1);
- }
- else
- {
- ans=max(ans,solve(i+1,j,i1,j1));
- ans=max(ans,solve(i,j-1,i1,j1));
- ans=max(ans,solve(i,j,i1+1,j1));
- ans=max(ans,solve(i,j,i1,j1-1));
- }
- return dp[i][j][i1][j1]=ans;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- test
- {
- cin>>a;
- cin>>b;
- memset(dp,-1,sizeof dp);
- cout<<"Case "<<cs<<": "<<solve(0,a.size()-1,0,b.size()-1)<<nl;
- }
- get_lost_idiot;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement