#include <bits/stdc++.h>
using namespace std;
struct SUBM {
void init(string& str, int _az = 27, char _base = 'a') {
az = _az, base = _base;
nxt = vector<vector<int>>(str.length() + 2, vector<int>(az, -1));
for (int i = str.length(); i >= 0; i--) {
for (int j = 0; j < az; j++)
nxt[i][j] = nxt[i + 1][j];
if (i != str.length())
nxt[i][ch(str[i])] = i + 1;
}
}
int ch(int idx) { return idx - base; }
int az, base;
vector<vector<int>> nxt;
} subm;
bool isSubsequence(string s, string t) {
subm.init(t, 26, 'a');
int cur = 0;
for (int i = 0; i < s.size(); i++) {
if (subm.nxt[cur][s[i] - 'a'] == -1) {
return false;
}
cur = subm.nxt[cur][s[i] - 'a'];
}
return true;
}
【小姿势】序列自动机
于 2020-07-28 00:24:03 首次发布