2777: [hnoi2004]language L language time limit:10 Sec Memory limit:128 MB
Submit:10 Solved:5
[Submit] [Status] [Web Board] Description punctuation appears later than the appearance of the text, so the previous language is no punctuation. Now all you have to deal with is an article with no punctuation.
A section of article T is made up of several lowercase letters. A word w is also composed of several lowercase letters. A Dictionary of D is a collection of several words.
We call an article T under a dictionary D to be understood, that is, if the article T can be divided into several parts, and each part is a word in dictionary d.
For example dictionary D includes the word {' is ', ' name ', ' What ', ' your '}, then the article ' Whatisyourname ' is understandable under dictionary D
Because it can be divided into 4 words: ' What ', ' is ', ' your ', ' name ', and each word belongs to dictionary d, and the article ' Whatisyouname '
Cannot be understood under dictionary D, but can be understood under dictionary d ' =d+{' you '. A prefix ' whatis ' of this passage can also be understood under dictionary D
And it is the longest prefix that can be understood under dictionary D.
Given a dictionary d, your program needs to determine whether several passages can be understood under dictionary D.
and gives the position of the longest prefix that can be understood under dictionary D. The first line of input inputs is two positive integers n and m, which indicates that there are n words in dictionary d, and that there is an M segment that needs to be processed.
The next n lines describe one word per line, and then each row of M lines describes an article.
Among them 1<=n, m<=20, each word length does not exceed 10, each paragraph length does not exceed 1M. Output for each paragraph of the input, you need to export the position of the longest prefix that the article can be understood in dictionary D. Sample Input
4 3isnamewhatyourwhatisyournamewhatisyounamewhaisyourname
Sample Output
1460 //entire article ' Whatisyourname ' can be understood by the prefix ' Whatis ' can be understood without any prefix to be understood
HINT Source
Exercises
Rubbish problem ruin my youth, with trie tree to mess up a bit just fine.
#include <iostream>#include<cstring>#include<cstdio>#defineMAXN 1049576using namespacestd;intN,m,ans,tot;CharS[MAXN];intson[maxn][ -],SUM[MAXN];BOOLF[MAXN];voidInsert () {scanf ("%s", s+1); intp=0; for(intI=1; S[i]; p=son[p][s[i]-'a'],i++)if(!son[p][s[i]-'a']) son[p][s[i]-'a']=++tot; SUM[P]=1;}voidChangeintx) { intp=0, aa=0; for(inti=x+1; S[i]; i++) { intv=son[p][s[i]-'a']; if(!V)return ; Else { if(sum[v]==1) f[i]=true; P=son[p][s[i]-'a']; } }}voidWork () {ans=0; scanf ("%s", s+1); Memset (F,false,sizeof(f)); intLen=strlen (s+1); f[0]=true;//cout<< "" <<len<<endl; for(intI=0; i<=len; i++) { if(f[i]==false)Continue; Ans=i; Change (i); } cout<<ans<<Endl;}intMain () {CIN>>n>>m; for(intI=1; i<=n; i++) insert (); for(intI=1; i<=m; i++) work ();}View Code
[HNOI2004] Language L Language