Advertisement
RaFiN_

Kaavi and Magic Spell-cf-1336C

Jul 1st, 2020
926
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. // https://www.youtube.com/watch?v=6OJdAemQSKo
  2. string s,t;ll dp[3005][3005];int n,m;
  3.  
  4. ll giveres(int pos,int l){
  5.     if(pos==-1) return 1ll;
  6.     ll &ret = dp[pos][l];
  7.     if(ret!=-1) return ret;
  8.     ret = 0;
  9.     if(l>=m||t[l]==s[pos]) ret = (ret + giveres(pos-1,l+1))%mod;
  10.     if(pos+l>=m||s[pos]==t[l+pos]) ret = (ret + giveres(pos-1,l))%mod;
  11.     return ret;
  12. }
  13.  
  14. int main()
  15. {
  16.     booster()
  17.     //read("input.txt");
  18.     cin >> s >> t;
  19.     ll ans = 0;
  20.     n = s.size();m = t.size();
  21.     mem(dp,-1);
  22.     for(int i = m-1;i<n;i++) {
  23.         ans = ans + giveres(i,0);
  24.         if(ans>=mod) ans %= mod;
  25.     }
  26.  
  27.     cout << ans << endl;
  28.  
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement