hdu-(1298 mobile-related dfs+ dictionary tree)

Source: Internet
Author: User

The main topic: In the past, the phone input method is very troublesome, because there are only 9 keys, and the letter has 26, so a key contains these letters at the same time, so that, in order to play a letter may have to press a few times. For example, key 5 has "JKL", if you want to enter K, then you have to double-press two times. This kind of input method is very troublesome. So a company invented the T9 technology input method. This input method contains many English words, it can be based on the frequency of the occurrence of English, whether there is such information, each letter just press once, you can have the desired preselection words. For example, suppose the input method has only one word "hell" built into it, then you just need to press 4355 to get out. Note that if there is a word hell, then all prefixes of this word, H, he, Hel, are also considered to be present.

Sample Input2 5 Hell 3 Hello 4 idea 8 next 8 Super 3 2 435561 43321 7 Another 5 contest 6 follow 3 give integer 6 new 1 4 Program 4 5 77647261 6391 4681 26684371 77771

Sample Outputscenario #1: I id hel hell hello i id ide idea Scenario #2: P PR Pro Prog progr progra program n NE new G in int C CO con cont anoth anothe Another p PR manually manually
#include <iostream>#include<cstdio>#include<cstring>#include<vector>using namespacestd;Const intKIND = -;Const intMAXN =15000;intCnt_node;vector<int>g[Ten];Charinput[ the];Charans[ the];intnum, Max;BOOLFlag;structnode{intprefix; Node*Next[kind]; voidinit () {prefix=0; Memset (Next,0,sizeof(next)); }}heap[maxn];inline node*NewNode () {heap[cnt_node].init (); return&heap[cnt_node++];}voidInsert (node *root,Char*STR,intN) {     for(Char*P=STR; *p; ++p) {        intch=*p-'a'; if(root->next[ch]==NULL) Root-&GT;NEXT[CH] =NewNode (); Root= root->Next[ch]; Root->prefix + =N; }}voidDFS (node *root,Char*STR,intPOS) {//str Save output result    if(Root==null)return; if(Pos >=num) {        if(Root->prefix >Max)            {strcpy (ans, str); Max=root->prefix; } Flag=true; return ; }    intu=input[pos]-'0';  for(intI=0; I<g[u].size (); ++i) {Str[pos]= g[u][i]+'a'; DFS (Root->next[g[u][i]], str, pos+1); Str[pos]=0; }}intMain () {intt,n,p,cas=1; Charstr[ the]; //keyboard settings, it seems that the complexity of writing ...     for(intI=0; i<Ten; ++i) g[i].clear (); g[2].push_back (0), g[2].push_back (1), g[2].push_back (2); g[3].push_back (3), g[3].push_back (4), g[3].push_back (5); g[4].push_back (6), g[4].push_back (7), g[4].push_back (8); g[5].push_back (9), g[5].push_back (Ten), g[5].push_back ( One); g[6].push_back ( A), g[6].push_back ( -), g[6].push_back ( -); g[7].push_back ( the), g[7].push_back ( -), g[7].push_back ( -), g[7].push_back ( -); g[8].push_back ( +), g[8].push_back ( -), g[8].push_back ( +); g[9].push_back ( A), g[9].push_back ( at), g[9].push_back ( -), g[9].push_back ( -); scanf ("%d",&T);  while(t--) {scanf ("%d",&N); printf ("Scenario #%d:\n", cas++); //Trie InitCnt_node=0; Node*root =NewNode ();  for(intI=0; i<n; ++i) {scanf ("%s%d",str,&p);        Insert (root, str, p); } scanf ("%d",&N);  for(intI=0; i<n; ++i) {scanf ("%s", input);  for(intj=0; J<strlen (Input)-1; ++j) {memset (str,0,sizeof(str)); Max=-1; Num=j+1; Flag=false; DFS (root, str,0); if(flag) puts (ans); ElsePuts"Manually"); } puts (""); } puts (""); }      return 0;}
View Code

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.