Bzoj 1212 Hnoi 2004 L Language Trie tree

Source: Internet
Author: User

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

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.