"Hdu 5510", "2015ACM/ICPC Asia Shenyang Station-Replay" Bazinga Test Instructions & Code (c + +)

Source: Internet
Author: User

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 + +)

Related Article

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.