版本比较
浅谈字符串
正文
增加 24 行删除 7 行
1234567891011121314151617181993 行未改动113114115116104117118119120121114 行未改动全部展开23623723823922724024124223024324424524624769 行未改动31731831932030832132232332432597 行未改动4234244254264144274284294174304314324334345 行未改动44044144244343144444544644744812 行未改动461462463464465466467468尝试写出最通俗的字符串学习笔记。
## 哈希
### 单哈希
别急。
```cpp cout << (lint)1e9 + 123 << endl; cout << (lint)1e15 + 37 << endl; cout << 29*(1ll<<57) + 1 << endl; cout << __LONG_LONG_MAX__ << endl;```
## kmp
>给定主串 $s$ 和模式串 $t$,求 $t$ 在 $s$ 中出现的位置和 $t$ 所有非空前缀的最长 border 长度。
93 行未改动
signed main(){ ios::sync_with_stdio(0); cin.tie(0);
// freopen("app.in","r",stdin); // freopen("app.out","w",stdout);
cin >> s >> t;114 行未改动全部展开
signed main(){ ios::sync_with_stdio(0); cin.tie(0);
// freopen("app.in","r",stdin); // freopen("app.out","w",stdout);
cin >> s;
n = s.size(); for(int i = 0; i < n; i++){69 行未改动我们用一个 vector 套结构体,结构体里面开一个长度为 $26$ 的数组。设一个这个类型的变量 $t_{i,j}$ 表示编号为 $i$ 对应字符 $j$ 的儿子的编号。
新塞进一个节点 $x$,我们设其父节点为 $fa$。如果 $t_{fa,x}=0$,则赋予 $x$ 新的编号 $\text{num}$,并令 $t_{fa,x}\gets\text{num}$。
我们发现,并不一定字符串的结尾都是叶子结点(例如 $\texttt{abc}$ 和 $\texttt{abcde}$),所以我们再设一个数组 $\text{cnt}_x$ 表示以编号为 我们发现,并不一定字符串的结尾都是叶子结点(例如 $\texttt{abc}$ 和 $\texttt{abcde}$),所以我们再设一个数组 $\text{cnt}_x$ 表示以编号为$x$ 的结点结尾的字符串有多少个。至此其实已经毕业了。
## fail 树(失配树)
97 行未改动
signed main(){ ios::sync_with_stdio(0); cin.tie(0);
// freopen("app.in","r",stdin); // freopen("app.out","w",stdout);
cin >> s; n = s.size(); s = "-" + s;
5 行未改动 break; } if(!nxt[i]) break; nxt[i] = nxt[nxt[i]]; } } }
for(int i = 1; i <= n; i++){ add(i+1,nxt[i]+1);12 行未改动```::::
## AC 自动机
### $\texttt{case 1}$
>给定主串 $s$ 和若干模式串 $\{t_i\}$,求多少个模式串在主串中出现过。