Topic Links:
http://acm.hdu.edu.cn/showproblem.php?pid=5510
Test Instructions:
Given n strings, the largest string is evaluated, and there is a string in the string that is smaller than the subscript in it is not his substring.
The following:
First can think of kmp+n^2 violent match, but the feeling will time out, so we need to add some pruning, water problem, not to be frightened by his data range.
Code:
#include <iostream>#include <algorithm>#include <stdio.h>#include <string.h>using namespace STD;intt,n,m,vis[505];intnex[505][2005];Chars[505][2005];voidGetnex (intID) {intlen=strlen(S[id]);intj=-1; for(intI=0; i<len;i++) { while(j!=-1&& s[id][i]!=s[id][j+1]) j=nex[id][j];if(s[id][j+1]==s[id][i] && i!=0) j + +; Nex[id][i]=j; }}BOOLKmpintIdsintIDT) {intlens=strlen(S[ids]);intLent=strlen(S[idt]);intj=-1; for(intI=0; i<lent;i++) { while(j!=-1&& s[ids][j+1]!=s[idt][i]) j=nex[ids][j];if(s[ids][j+1]==s[idt][i]) J + +;if(j==lens-1)return 1; }return 0;}intMain () {inttot=0;scanf("%d", &t); while(t--) {tot++;scanf("%d", &n); for(intI=1; i<=n;i++)scanf('%s ', S[i]); for(intI=1; i<=n;i++) {vis[i]=0; Getnex (i); }intans=-1; for(intI=2; i<=n;i++) { for(intj=i-1; j>=1; j--) {if(vis[j]==1)Continue;if(KMP (J,i)) {vis[j]=1;//cout<<i<< ' <<j<<endl;}Else{ans=i; Break; } } }printf("Case #%d:%d\n", Tot,ans); }}
"Hdu 5510", "2015ACM/ICPC Asia Shenyang Station-Replay" Bazinga Test Instructions & Code (c + +)