Advertisement
Kevin_Zhang

Untitled

Nov 20th, 2021
1,083
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. #define pb emplace_back
  5. #define AI(i) begin(i), end(i)
  6. template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
  7. template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
  8. #ifdef KEV
  9. #define DE(args...) kout("[ " + string(#args) + " ]", args)
  10. void kout() { cerr << endl; }
  11. template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
  12. template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
  13. #else
  14. #define DE(...) 0
  15. #define debug(...) 0
  16. #endif
  17.  
  18. const int MAX_N = 110, MAX_M = 10010, MOD = 998244353, SIG = 26, inf = 1e9;
  19.  
  20. int n, m;
  21. char A[MAX_M], B[MAX_M];
  22. array<int,SIG> nxt[MAX_M];
  23.  
  24. //int dp[MAX_M][MAX_N][MAX_M];
  25. int dp[MAX_N][MAX_M];
  26.  
  27. void add(int &a, int b) {
  28.     a = (a + b) % MOD;
  29. }
  30.  
  31. int32_t main() {
  32.     ios_base::sync_with_stdio(0), cin.tie(0);
  33.  
  34.     {
  35.         string a, b;
  36.         cin >> a >> b;
  37.         for (int i = 0;i < a.size();++i)
  38.             A[i+1] = a[i];
  39.         for (int i = 0;i < b.size();++i)
  40.             B[i+1] = b[i];
  41.     }
  42.     //cin >> (A+1) >> (B+1);
  43.  
  44.     n = strlen(A+1), m = strlen(B+1);
  45.  
  46.     fill(AI(nxt[m+1]), inf);
  47.  
  48.     for (int i = m;i >= 1;--i) {
  49.         nxt[i] = nxt[i+1];
  50.         nxt[i][ B[i]-'a' ] = i;
  51.     }
  52.     nxt[0] = nxt[1];
  53.  
  54.     dp[0][0] = 1;
  55.  
  56.     for (int i = 0;i <= n;++i)
  57.         for (int j = 0;j <= m;++j) {
  58.             for (char l = 'a';l <= 'z';++l) {
  59.                 int ni = min(n, i + (l==A[i+1])), nj = nxt[j+1][l - 'a'];
  60.                 if (nj > m) continue;
  61.                 add(dp[ni][nj], dp[i][j]);
  62.             }
  63.         }
  64.     int res = 0;
  65.  
  66.     for (int i = 0;i <= m;++i)
  67.         add(res, dp[n][i]);
  68.  
  69.     cout << res << '\n';
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement