"POJ 3693" Maximum repetition substring repeats the largest number of consecutive repeating substrings

Source: Internet
Author: User

The example in the thesis of the suffix array is not understood,,,

Ask for a repetition of the most consecutive repeating substring, and because to find the most forward, so sweep when the record maximum number of repetitions of $ans$, after sweeping and then from the beginning of the violence swept to the end of the $ans$ to find the number of repetitions of the first substring of the beginning of the break output can be

#include <cmath> #include <cstdio> #include <cstring> #include <algorithm>using namespace std; const int n = 100003;int t1[n], T2[n], c[n];void st (int *x, int *y, int *sa, int n, int m) {int i;for (i = 0; i < m; ++i ) C[i] = 0;for (i = 0; i < n; ++i) ++c[x[y[i]]];for (i = 1; i < m; ++i) c[i] + = c[i-1];for (i = n-1; I >= 0; I. ) Sa[--c[x[y[i]] [y[i];} void mkhz (int *a, int *sa, int n, int m) {int *x = t1, *y = t2, *t, I, J, p;for (i = 0; i < n; ++i) x[i] = A[i], y[i] = I;st (x, y, SA, N, m); for (P = 1, j = 1; p < n; j <<= 1, m = p) {for (P = 0, i = n-j; i < n; ++i) y[p++] = I;fo R (i = 0; i < n; ++i) if (Sa[i] >= j) y[p++] = Sa[i]-j;st (x, y, SA, N, m); for (t = x, x = y, y = t, p = 1, x[sa[0]] = 0, i = 1; I < n; ++i) x[sa[i] [] = Y[sa[i] [y[sa[i-1]] && Y[sa[i] + j] = = Y[sa[i-1] + j]? P-1: p++;}}  void Mkh (int *r, int *sa, int *rank, int *h, int n) {int I, j, k = 0;for (i = 1; I <= n; ++i) rank[sa[i]] = i;for (i = 1; I <= N h[rank[i++]] = k) for (K---k:0, j = sa[rank[i]-1]; R[i + K] = = R[j + K]; ++k);} Char S[n];int A[n], rank[n], sa[n], h[n], N, pro = 0, f[n][30], ans, CNT, aa[n];void Mkst () {for (int i = 1; I <= N; ++i ) F[i][0] = h[i];int k = Floor (log (double) n)/log (2.0)), for (int j = 1, j <= K; ++j) for (int i = 1; I <= n; ++i) {if (i + (1 << J)-1 > N) break;f[i][j] = min (f[i][j-1], f[i + (1 << (j-1))][j-1]);}} int Q (int l, int r) {L = Rank[l]; r = rank[r];if (L > R) Swap (L, R), ++l;int k = Floor (log (double) (r-l + 1))/log (2 .0)); return min (F[l][k], F[r-(1 << k) + 1][k]);} int main () {while (scanf ("%s", S + 1), s[1]! = ' # ') {printf ("Case%d:", ++pro), n = strlen (s + 1), and for (int i = 1; I <= N; ++i) A[i] = s[i];mkhz (A, SA, n + 1, 1), Mkh (A, SA, rank, h, N), Mkst (), ans = 0, cnt = 0;for (int l =; l < n; ++l) for (i NT i = 1; I <= n-l; i + = l) {int k = Q (i, i + L), int now = k/l + 1;int to = i-(l-k% L), if (To > 0 && k L) if (q + L) >= now ++now;if (now > ans) {aa[cnt = 1] = L;ans = Now,} else if (now = = ans) {aa[++cnt] = l;}} int to = 0, Len = 0;for (int i = 1; I <= n; ++i) for (int j = 1; j <= cnt; ++j) {int k = Q (Sa[i], sa[i] + aa[j]); if (k >= (ans-1) * Aa[j]) {to = Sa[i];len = ans * aa[j];i = n;break;}} for (int i = to; I < to + len; ++i) Putchar (S[i]);p UTS (""); return 0;}

Finally a 233.

"POJ 3693" Maximum repetition substring repeats the largest number of consecutive repeating substrings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.