Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- created: 2023-02-21-19.32.46
- ***/
- #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 all(we) we.begin(),we.end()
- #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
- #define nl '\n'
- const ll mod=1e9+7;
- string a,b,c;
- ll dp[101][101][101][3],v[101][101][101][3];
- ll ts=1,s1,s2,s3;
- ll solve(ll ai,ll bi,ll ci,ll f)
- {
- if(ci==s3) return 1ll;
- if(v[ai][bi][ci][f]==ts) return dp[ai][bi][ci][f];
- ll ans=0;
- if(f==0)
- {
- ans+=solve(ai,bi,ci,1);
- if(ans>=mod) ans-=mod;
- ans+=solve(ai,bi,ci,2);
- if(ans>=mod) ans-=mod;
- }
- else if(f==1)
- {
- if(ai==s1) return 0;
- if(a[ai]==c[ci])
- {
- ans+=solve(ai+1,bi,ci+1,0);
- if(ans>=mod) ans-=mod;
- }
- ans+=solve(ai+1,bi,ci,1);
- if(ans>=mod) ans-=mod;
- }
- else
- {
- if(bi==s2) return 0;
- if(b[bi]==c[ci])
- {
- ans+=solve(ai,bi+1,ci+1,0);
- if(ans>=mod) ans-=mod;
- }
- ans+=solve(ai,bi+1,ci,2);
- if(ans>=mod) ans-=mod;
- }
- if(ans>=mod) ans-=mod;
- v[ai][bi][ci][f]=ts;
- return dp[ai][bi][ci][f]=ans;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- test
- {
- cin>>a>>b>>c;
- s1=a.size(),s2=b.size(),s3=c.size();
- cout<<"Case "<<cs<<": "<<solve(0ll,0ll,0ll,0ll)<<nl;
- ts++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement