Bzoj 1055 [HAOI2008] Toy name

Source: Internet
Author: User

1055: [HAOI2008] Toy name time limit:10 Sec Memory limit:162 MB
submit:1119 solved:653
[Submit] [Status] [Discuss] Description

Someone has a set of toys and wants to name the toys. First he chooses any one of the four letters of wing as the basic name of the toy. Then he will, according to his preference, use any of the letters in the name "WING" to replace any of the two letters, so that his name can be extended very long. Now, he would like to ask you to guess a very long name, which may have been initially distorted by which letters.

Input

The first line is four integers w, I, N, G. Indicates that each letter can be replaced by a few two letters. The next W line, two letters per line, indicates that W can be substituted with these two letters. Next I line, two letters per line, indicating I can be replaced with these two letters. The next n lines, two letters per line, indicate that n can be substituted with these two letters. The next G line, two letters per line, indicates that G can be substituted with these two letters. The last line is a string that does not exceed Len in length. denotes the name of the toy.

Output

A line of strings, which may be distorted by the name of the letter. (output in the order of wing) if the given name cannot be distorted by any one letter, then output "The name is wrong!"

Sample Input1 1 1 1
Ii
Ww
Ww
IG
IIIISample OutputinchHINT

W can become II so IIII can be shrunk into WW in can become WW so WW can be shrunk to I or n so the final answer should be output in the order of "WING"

[Data Range]

100% data satisfies len<=200,w, I, N, g<=16


Source

Solving: Interval DP, L~R with a group can, each use a dictionary to divide the interval.

And because there is no solution to the situation wa a pitch = = ...

1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <stack>6#include <queue>7#include <cstring>8 #definePAU Putchar (")9 #defineENT Putchar (' \ n ')Ten using namespacestd; One Const intmaxn= $+Ten, inf=-1u>>1; A intIdCharch) { -     if(ch=='W')return 0; -     if(ch=='I')return 1; the     if(ch=='N')return 2; -     if(ch=='G')return 3; -     return-1; - } + voidPrincinta) { -     if(!a) Putchar ('W'); +     Else if(a==1) Putchar ('I'); A     Else if(a==2) Putchar ('N'); at     Else if(a==3) Putchar ('G'); -     return; - } - intt[4],tx[4][ -][2],ARR[MAXN];intdp[4][MAXN][MAXN]; - BOOLSolveintAintLintR) { -     int&res=dp[a][L][R];if(res!=-1)returnRes; in     if(L==R)return(Res= (arr[l]==a)); -      for(inti=l;i<r;i++){ to          for(intj=0; j<t[a];j++){ +             if(Solve (tx[a][j][0],l,i) &&solve (tx[a][j][1],i+1, R))return(res=true); -         } the}return(res=false); * } $InlineintRead () {Panax Notoginseng     intx=0;BOOLsig=1;CharCh=GetChar (); -      for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') sig=0; the      for(; isdigit (ch); Ch=getchar ()) x=Ten*x+ch-'0'; +     returnsig?x:-x; A } theInlinevoidWriteintx) { +     if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; -     intlen=0, buf[ -]; while(x) buf[len++]=x%Ten, x/=Ten; $      for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; $ } - CharS[MAXN]; - intMain () { the      for(intI=0;i<4; i++) t[i]=read (); -      for(intI=0;i<4; i++){Wuyi          for(intj=0; j<t[i];j++){ thescanf"%s", s); tx[i][j][0]=id (s[0]); tx[i][j][1]=id (s[1]); -         } Wu     } -scanf"%s", s); About      for(intI=0; s[i];i++) Arr[i]=id (S[i]);intlen=strlen (s); $memset (dp,-1,sizeof(DP));BOOLflag=false; -      for(intI=0;i<4; i++){ -         if(Solve (I,0, len-1)) Princ (i), flag=true; -     } A     if(!flag) puts ("The name is wrong!"); +     return 0; the}

Bzoj 1055 [HAOI2008] Toy name

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.