Take a look at the string and leave it as a souvenir.

Source: Internet
Author: User

Question poj1226 (violent, suffix array)

 

 

// Obtain the maximum length of a substring for a given n strings, // make it or its reverse string appear in each string. // Train of thought: first obtain the sho string sho [], and then enumerate the answer length ans (LEN ~ 1 ). // Therefore, Sho [] is divided into Len-ans + 1 sub-string POS [], // obtain the reverse string inv [] Of these strings respectively, // determine whether POS [] and inv [] appear in all strings. # Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; struct TT {char s [110]; int Len;} AA [110]; struct TTT {char a [110], B [110]; int Len;} BB [10000]; int CMP (TTT X, TTT y) {return X. len> Y. len ;}; int main () {int t; scanf ("% d", & T); While (t --) {int N; scanf ("% d ", & N); int Minn = 210000, minid = 0; For (INT I = 0; I <n; I ++) {scanf ("% s ", AA [I]. s); AA [I]. len = strlen (AA [I]. s); If (AA [I]. len <Minn) Minn = AA [I]. len, minid = I;} int id = 0; For (INT I = 0; I <Minn; I ++) {for (Int J = I; j <Minn; j ++) {int KK = 0; For (int K = I; k <= J; k ++) bb [ID]. A [Kk ++] = AA [minid]. s [k]; bb [ID]. A [Kk] = '\ 0'; KK = 0; For (int K = J; k> = I; k --) bb [ID]. B [Kk ++] = AA [minid]. s [k]; bb [ID]. B [Kk] = '\ 0'; bb [ID]. len = KK; Id ++ ;}} sort (BB, BB + id, CMP); int exist, ANS = 0; For (int ii = 0; II <ID; II ++) {exist = 1; for (INT I = 0; I <n; I ++) {If (strstr (AA [I]. s, BB [II]. a) = 0 & strstr (AA [I]. s, BB [II]. b) = 0) {exist = 0; break ;}} if (exist) {ans = BB [II]. len; break ;}} printf ("% d \ n", ANS) ;}return 0 ;}
View code

 

Take a look at the string and leave it as a souvenir.

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.