盏记,洁面刷,车站 张磊
void add() { int len = strlen(s + 1); int now = 0; for(int i = 1;i <= len;++i) { if(!trie[now][s[i] - 'a']) trie[now][s[i] - 'a'] = ++tot; now = trie[now][s[i] - 'a']; } val[now]++; }
void build() { for(int i = 0;i < 26;++i) if(trie[0][i]) fail[trie[0][i]] = 0,q.push(trie[0][i]); while(!q.empty()) { int u = q.front();q.pop(); for(int i = 0;i < 26;++i) { if(trie[u][i]) fail[trie[u][i]] = trie[fail[u]][i],q.push(trie[u][i]); else trie[u][i] = trie[fail[u]][i]; } } }
int query() { int now = 0; int ans = 0; int len = strlen(s + 1); for(int i = 1;i <= len;++i) { now = trie[now][s[i] - 'a']; for(int j = now;j && val[j] != -1;j = fail[j]) ans += val[j],val[j] = -1; } return ans; }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
如何在没有core文件的情况下用dmesg+addr2line定位段错误
用QT制作3D点云显示器——QtDataVisualization
网友评论