序列自动机-创新互联

#include 
using namespace std;
const int MaxN = 1000000 + 5;
int N, L;
char str[MaxN], str2[MaxN];
struct SAM {
  int cntv;
  int nxt[MaxN];
  int last[26], ch[26][MaxN];
  SAM() { nxt[0] = -1; }
  inline void insert(int c) {
    cntv++; nxt[cntv] = last[c];
    for (int i = 0; i < 26; ++i)
      for (int p = last[i]; p != -1 && ch[c][p] == 0; p = nxt[p])
        ch[c][p] = cntv;
    last[c] = cntv;
  }
  inline bool check(int u, int x) {
    if (x == L) return true;
    int c = str2[x] - 'a';
    if (ch[c][u] == 0) return false;
    return check(ch[c][u], x + 1);
  }
} T;
void init() {
  scanf("%s", str);
  scanf("%d", &N);
  for (int i = 0; str[i]; ++i) T.insert(str[i] - 'a');
}
void solve() {
  for (int i = 1; i <= N; ++i) {
    scanf("%s", str2);
    L = strlen(str2);
    puts(T.check(0, 0) ? "Yes" : "No");
  }
}
int main() {
  init();
  solve();
  return 0;
}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

创新互联公司专业为企业提供城中网站建设、城中做网站、城中网站设计、城中网站制作等企业网站建设、网页设计与制作、城中企业网站模板建站服务,10多年城中做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
网站标题:序列自动机-创新互联
本文来源:http://scyanting.com/article/dsphig.html