Codeforces 633 C Spy syndrome 2 Dictionary tree

Source: Internet
Author: User

Test instructions: It's better to understand.

Analysis: Invert each word, build a dictionary tree, and then violently match the encrypted string

Note: Then I just don't understand, the above kind can, and the time is very short, but I think vice versa.

The first I wrote was to reverse the cipher string, and then the word was built into the dictionary tree, and then it was tle, and it could have been written backwards.

Really baffled, and then I guess the number of words is probably less

#include <cstdio>#include<iostream>#include<cstring>#include<cstdlib>#include<vector>#include<string>#include<algorithm>using namespaceStd;typedefLong LongLL;Const intn=1000000+5;Chars[10005];Charstr[100005][1005];intlen[100005];inttrie[n][ -],mk[n];intans[10005],tot,cnt,m,n;voidAddintx) {    intnow=0;  for(inti=len[x]-1; i>=0; --i) {Chartmp=Str[x][i]; if(tmp<'a'|| Tmp>'Z') TMP+='a'-'A'; intp=tmp-'a'; if(!trie[now][p]) trie[now][p]=++CNT; now=Trie[now][p]; } Mk[now]=x;}voidSolveintPOS) {    if(pos==N) { for(intI=1; i<tot; ++i) printf ("%s", Str[ans[i]]); printf ("%s\n", Str[ans[tot]]); Exit (0); }    intnow=0;  for(inti=pos+1; i<=n; ++i) {intp=s[i]-'a'; now=Trie[now][p]; if(!now) Break; if(Mk[now]) {ans[++tot]=Mk[now]; Solve (POS+Len[mk[now]]); --tot; }    }}intMain () {scanf ("%d%s", &n,s+1);//for (int i=1; i<=n/2; ++i)//swap (s[i],s[n-i+1]);scanf"%d",&m);  for(intI=1; i<=m; ++i) {scanf ("%s", Str[i]); Len[i]=strlen (Str[i]);    Add (i); } Solve (0); return 0;}
View Code

Codeforces 633 C Spy syndrome 2 Dictionary tree

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.