Title effect: give some words. And a few sentences, when and only if the sentence can be cut the child can translate the dictionary, which means that the child will be translated.
Find the longest prefix length can be translated.
Mind: Use the trie tree brush. You can brush to the longest place where the longest string can be translated.
PS: On the Bzoj trie unexpectedly than AC own active machine fast. My slag code has been brushed to the first article.
。
CODE:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace Std struct trie{Trie *son[27]; BOOL End; Trie () {memset (son,null,sizeof (son)); end = false; }}*root = new Trie (); int Words,cnt;char s[1 << 20|100],temp[20];bool f[1 << 20|100]; inline void Insert (char *s) {Trie *now = root; while (*s! = ')} {if (Now->son[*s-' a '] = = NULL) now->son[*s-' a '] = new Trie (); now = now->son[*s-' a ']; ++s; } Now->end = true;} inline void Ask (char *s,int i) {Trie *now = root; int t = 0; while (*s! = ')} {if (Now->son[*s-' a '] = = NULL) return; now = now->son[*s-' a ']; ++s; ++t; if (now->end) F[i + t] = true; } if (now->end) F[i + t] = true;} inline int work () {memset (f,false,sizeof (f)); F[0] = true; int re = 0,length = strlen (s + 1); for (int i = 0; I <= leNgth; ++i) {if (!f[i]) continue; re = i; Ask (s + i + 1,i); } return re;} int main () {cin >> words >> CNT; for (int i = 1; I <= words; ++i) {scanf ("%s", temp); Insert (temp); } for (int i = 1; I <= cnt; ++i) {scanf ("%s", S + 1); printf ("%d\n", Work ()); } return 0;}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Bzoj 1212 Hnoi 2004 L Language Trie tree