Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- #define pb emplace_back
- #define AI(i) begin(i), end(i)
- template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
- template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
- #ifdef KEV
- #define DE(args...) kout("[ " + string(#args) + " ]", args)
- void kout() { cerr << endl; }
- template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
- template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
- #else
- #define DE(...) 0
- #define debug(...) 0
- #endif
- const int MAX_N = 110, MAX_M = 10010, MOD = 998244353, SIG = 26, inf = 1e9;
- int n, m;
- char A[MAX_M], B[MAX_M];
- array<int,SIG> nxt[MAX_M];
- //int dp[MAX_M][MAX_N][MAX_M];
- int dp[MAX_N][MAX_M];
- void add(int &a, int b) {
- a = (a + b) % MOD;
- }
- int32_t main() {
- ios_base::sync_with_stdio(0), cin.tie(0);
- {
- string a, b;
- cin >> a >> b;
- for (int i = 0;i < a.size();++i)
- A[i+1] = a[i];
- for (int i = 0;i < b.size();++i)
- B[i+1] = b[i];
- }
- //cin >> (A+1) >> (B+1);
- n = strlen(A+1), m = strlen(B+1);
- fill(AI(nxt[m+1]), inf);
- for (int i = m;i >= 1;--i) {
- nxt[i] = nxt[i+1];
- nxt[i][ B[i]-'a' ] = i;
- }
- nxt[0] = nxt[1];
- dp[0][0] = 1;
- for (int i = 0;i <= n;++i)
- for (int j = 0;j <= m;++j) {
- for (char l = 'a';l <= 'z';++l) {
- int ni = min(n, i + (l==A[i+1])), nj = nxt[j+1][l - 'a'];
- if (nj > m) continue;
- add(dp[ni][nj], dp[i][j]);
- }
- }
- int res = 0;
- for (int i = 0;i <= m;++i)
- add(res, dp[n][i]);
- cout << res << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement