HDU 4416 Good Article good sentence

Source: Internet
Author: User

Good Article good sentencetime limit:3000msmemory limit:32768kbthis problem would be judged onHDU. Original id:4416
64-bit integer IO format: %i64d Java class name: Main In middle school, teachers used to encourage us to pick up pretty sentences so that we could apply those sentences Own articles. One of my classmates Zengxiao Xian, wanted to get sentences which is different from that of others, because he thought th e distinct pretty sentences might benefit him a lot of get a high score in his article.
Assume that all of the sentences came from some articles. Zengxiao Xian intended to pick from article A. The number of his classmates is N. The i-th classmate picked from article Bi. Now Zengxiao Xian wants to know what many different sentences she could pick from article A which don ' t belong to either of Her classmates? Article. To simplify the problem, Zengxiao Xian wants to know how many different strings, which was the substring of string A, but I s not substring of either of string Bi. Of course, you'll help him, won ' t?
InputThe first line contains an integer T, the number of test data.
For each test data
The first line contains an integer meaning the number of classmates.
The second line is the string A; The next n lines,the ith line input string Bi.
The length of the string A does not exceed 100,000 characters, the sum of total length of all strings Bi does not exceed 100,000, and assume all string consist only lowercase characters ' a ' to ' Z '.
OutputFor each case, print the case number and the number of substrings that Zengxiao Xian can find.Sample Input
32abababba1aaabbb2aaaaaaaaa
Sample Output
Case 1:3case 2:3case 3:1
SourceACM/ICPC Asia Regional Hangzhou Online Test instructions: Give a string S and a series of string t1~tn, ask how many different substrings in s are satisfied that it is not a substring of any of the strings in T1~tn problem solving: suffix automata
1#include <bits/stdc++.h>2 using namespacestd;3typedefLong LongLL;4 Const intMAXN =100010;5 intsa[maxn<<1],C[MAXN];6 structnode{7     intson[ -],f,len,deep;8     voidinit () {9memset (son,-1,sizeofson);TenDeep = Len =0; Onef =-1; A     } - }; - structsam{ theNode e[maxn<<1]; -     intTot,last; -     intNewNodeintLen =0){ - e[tot].init (); +E[tot].len =Len; -         returntot++; +     } A     voidinit () { attot = last =0; - NewNode (); -     } -     voidAddintc) { -         intp = LAST,NP = NewNode (E[p].len +1); -          while(P! =-1&& E[p].son[c] = =-1){ inE[P].SON[C] =NP; -p =e[p].f; to         } +         if(p = =-1) E[NP].F =0; -         Else{ the             intQ =E[p].son[c]; *             if(E[p].len +1= = E[q].len) E[np].f =Q; $             Else{Panax Notoginseng                 intNQ =NewNode (); -E[NQ] =E[q]; theE[nq].len = E[p].len +1; +E[Q].F = E[NP].F =NQ; A                  while(P! =-1&& E[p].son[c] = =q) { theE[P].SON[C] =NQ; +p =e[p].f; -                 } $             } $         } -Last =NP; -     } the     voidUpdateChar*str) { -         intln =0, p =0;Wuyi          for(inti =0; Str[i]; ++i) { the             intc = Str[i]-'a'; -             if(E[p].son[c]! =-1){ Wup =E[p].son[c]; -E[p].deep = Max (e[p].deep,++LN); About}Else{ $                  while(P! =-1&& E[p].son[c] = =-1) p =e[p].f; -                 if(p = =-1) p = LN =0; -                 Else{ -ln = E[p].len +1; Ap =E[p].son[c]; +E[p].deep =Max (E[P].DEEP,LN); the                 } -             } $         } the     } the LL count () { theLL ret =0; the          for(inti = tot-1; i >0; --i) { -             intv =Sa[i]; in             if(E[v].deep >0){ theE[e[v].f].deep =Max (e[e[v].f].deep,e[v].deep); the                 if(E[v].deep < E[v].len) ret + = E[v].len-E[v].deep; About}ElseRET + = E[v].len-E[e[v].f].len; the         } the         returnret; the     } + }sam; - CharSTR[MAXN]; the intMain () {Bayi     intKase,m,cs =1; thescanf"%d",&Kase); the      while(kase--){ -scanf"%d%s",&m,str); - sam.init (); the          for(inti =0; Str[i]; ++i) Sam.add (Str[i]-'a'); theMemset (c,0,sizeofc); the          for(inti =0; i < Sam.tot; ++i) c[sam.e[i].len]++; the          for(inti =1, Len = strlen (str); I <= Len; ++i) C[i] + = c[i-1]; -          for(inti = sam.tot-1; I >=0; -i) Sa[--c[sam.e[i].len]] =i; the          while(m--){ thescanf"%s", str); the sam.update (str);94         } theprintf"Case %d:%i64d\n", cs++, Sam.count ()); the     } the     return 0;98}
View Code

HDU 4416 Good Article good sentence

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.