Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaf01de8

Browse files
authored
fix some formatting
1 parentfaf8510 commitaf01de8

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

‎src/string/suffix-automaton.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,9 @@ This is demonstrated succinctly below:
502502
503503
```cpp
504504
long long get_diff_strings(){
505-
lltot{};
506-
for(int i=1;i<sz;i++) {
507-
tot+=st[i].len-st[st[i].link].len;
505+
long longtot = 0;
506+
for(int i = 1; i <sz;i++) {
507+
tot +=st[i].len -st[st[i].link].len;
508508
}
509509
return tot;
510510
}
@@ -530,24 +530,24 @@ We take the answer of each adjacent vertex $w$, and add to it $d[w]$ (since ever
530530
Again this task can be computed in $O(length(S))$ time.
531531

532532
Alternatively, we can, again, take advantage of the fact that each state $v$ matches to substrings of length $[minlen(v),len(v)]$.
533-
Since $minlen(v) = 1 + len(link(v))$ and the arithmetic series formula $S_n = n* (a_1+a_n) / 2$ (where $S_n$ denotes the sum of $n$ terms, $a_1$ representing the first term, and $a_n$ representing the last), we can compute the length of substrings at a state in constant time. We then sum up these totals for each state $v \neq t_0$ in the automaton. This is shown by the code below:
533+
Since $minlen(v) = 1 + len(link(v))$ and the arithmetic series formula $S_n = n\cdot \frac{a_1+a_n}{2}$ (where $S_n$ denotes the sum of $n$ terms, $a_1$ representing the first term, and $a_n$ representing the last), we can compute the length of substrings at a state in constant time. We then sum up these totals for each state $v \neq t_0$ in the automaton. This is shown by the code below:
534534

535535
```cpp
536536
longlongget_tot_len_diff_substings() {
537-
long long tot{};
538-
for(int i=1;i<sz;i++) {
539-
long long shortest=st[st[i].link].len+1;
540-
long long longest=st[i].len;
537+
long long tot = 0;
538+
for(int i = 1; i <sz;i++) {
539+
long long shortest =st[st[i].link].len +1;
540+
long long longest =st[i].len;
541541
542-
long long num_strings=longest-shortest+1;
543-
544-
long long cur=num_strings*(longest+shortest)/2;
542+
long long num_strings = longest - shortest + 1;
543+
long long cur = num_strings * (longest + shortest) / 2;
545544
tot += cur;
546545
}
547546
return tot;
548547
}
549548
```
550-
This approaches runs in $O(length(S))$ time, but experimentally runs 20x faster than the memoized dynamic programming version on randomized strings. It requires no extra space and not recursion.
549+
550+
This approaches runs in $O(length(S))$ time, but experimentally runs 20x faster than the memoized dynamic programming version on randomized strings. It requires no extra space and no recursion.
551551

552552
###Lexicographically $k$-th substring {data-toc-label="Lexicographically k-th substring"}
553553

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp