Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- created: 2022-08-26-21.32.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'
- ll dp[35][35];
- ll dp1[35][35][100];
- string x,y;
- ll n,m;
- ll solve(ll i,ll j)
- {
- if(i>=n || j>=m) return 0;
- if(dp[i][j]!=-1) return dp[i][j];
- ll ans=0;
- if(x[i]==y[j])
- {
- ans=max(ans,1+solve(i+1,j+1));
- }
- else
- {
- ans=max(ans,solve(i,j+1));
- ans=max(ans,solve(i+1,j));
- }
- return dp[i][j]=ans;
- }
- ll solve1(ll i,ll j,ll l)
- {
- if(i==n && j!=m) return solve1(i,j+1,l-1);
- if(i!=n && j==m) return solve1(i+1,j,l-1);
- if(i==n && j==m && l==0) return 1;
- if(i==n && j==m && l) return 0;
- if(dp1[i][j][l]!=-1) return dp1[i][j][l];
- ll ans=0;
- if(x[i]==y[j])
- {
- ans=solve1(i+1,j+1,l-1);
- }
- else
- {
- ans=solve1(i+1,j,l-1) + solve1(i,j+1,l-1);
- }
- return dp1[i][j][l]=ans;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- test
- {
- ll i,j,k,len=0;
- cin>>x>>y;
- n=x.size();
- m=y.size();
- memset(dp,-1,sizeof dp);
- memset(dp1,-1,sizeof dp1);
- len=n+m-solve(0,0);
- cout<<"Case "<<cs<<": "<<len<<" "<<solve1(0,0,len)<<nl;
- }
- get_lost_idiot;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement