本网页所有文字内容由 imapbox邮箱云存储,邮箱网盘, iurlBox网页地址收藏管理器 下载并得到。
ImapBox 邮箱网盘 工具地址: https://www.imapbox.com/download/ImapBox.5.5.1_Build20141205_CHS_Bit32.exe
PC6下载站地址:PC6下载站分流下载
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox 网页视频 工具地址: https://www.imapbox.com/download/ImovieBox4.7.0_Build20141115_CHS.exe
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
#include <cstdio> #include <cstdlib> #include <cstring> #include <queue> using namespace std; const int N = 5e5+5, M = 1e6+5; struct Trie { Trie *next[26]; Trie *fail; int val; }tree[N]; queue <Trie *> q; int idx[128]; class ac_auto { private: int nxt; Trie *root; public: ac_auto() { nxt = 0; root = add(); } Trie *add() { memset(&tree[nxt], 0, sizeof(Trie)); tree[nxt].fail = root; return &tree[nxt++]; } void insert(char *s) { Trie *rt = root; int len = strlen(s); for(int i = 0; i < len; i++) { int c = idx[s[i]+0]; if(!rt->next[c]) rt->next[c] = add(); rt = rt->next[c]; } rt->val++; } void get_f() { queue <Trie *> q; q.push(root); root->fail = NULL; while(!q.empty()) { Trie *u = q.front(); q.pop(); for(int c = 0; c < 26; c++) { if(u->next[c]) { Trie *f = u->fail; while(f) { if(f->next[c]) { u->next[c]->fail = f->next[c]; break; } f = f->fail; } if(!f) u->next[c]->fail = root; q.push(u->next[c]); } } } } int match(char *s) { Trie *rt = root; int len = strlen(s), ret = 0; for(int i = 0; i < len; i++) { int c = idx[s[i]+0]; while(!rt->next[c] && rt != root) rt = rt->fail; rt = rt->next[c]; if(!rt) rt = root; Trie *p = rt; while(p != root) { if(p->val) { ret += p->val; p->val = 0; } else break; p = p->fail; } } return ret; } }; void haxi() { for(int i = 0; i < 26; i++) idx['a'+i] = i; } int main() { haxi(); int T, m; char str[M]; scanf("%d", &T); while(T--) { ac_auto ac; scanf("%d", &m); while(m--) { scanf("%s", str); ac.insert(str); } ac.get_f(); scanf("%s", str); int ans = ac.match(str); printf("%d/n", ans); } return 0; }
阅读和此文章类似的: 程序员专区