Memory Search Special--nkoj3748 toy name

Source: Internet
Author: User
Tags bool time limit
P3748 Toy Name
Time limit:-MS space limit: 65536 KB
Evaluation instructions: time limit 1000ms
Problem 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 Format

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 Format

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 Input

1 1 1 1
Ii
Ww
Ww
IG
IIII
Sample Output

Inch
Tips

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


#include <cstdio> #include <iostream> #include <algorithm> #include <cstdlib> #include <
Cstring> using namespace std;
BOOL Flag=false;
int W,i,n,g,len;
int a[10][20][3];
int num[10];
BOOL F[205][205][10];
BOOL MARK[205][205][10];
int oi[205];
Char p[5]={' * ', ' W ', ' I ', ' N ', ' G '};
	int ID (char b) {if (b== ' W ') return 1;
	else if (b== ' I ') return 2;
	else if (b== ' N ') return 3;
else if (b== ' G ') return 4;
	} bool DP (int l,int r,int k) {int h,j;
	if (Mark[l][r][k]) return f[l][r][k];
	Mark[l][r][k]=true;
	if (l==r&&oi[l]==k) {return f[l][r][k]=true; } for (h=1;h<=num[k];h++) {for (j=l;j<r;j++) {if (DP (l,j,a[k][h][1]) &AMP;&AMP;DP (j+1,r,a[k][h][2])) {return F L [R]
			[K]=true;
}}} return f[l][r][k]=false;
	} int main () {int j,k;
	string S;
	cin>>w>>i>>n>>g;
	Num[1]=w;
	Num[2]=i;
	Num[3]=n;
	num[4]=g;
		for (j=1;j<=w;j++) {char ch;
		cin>>ch;
		A[1][j][1]=id (CH);
		cin>>ch;
	A[1][j][2]=id (CH); } for (j=1;j<=i;j++) {char ch;
		cin>>ch;
		A[2][j][1]=id (CH);
		cin>>ch;
	A[2][j][2]=id (CH);
		} for (j=1;j<=n;j++) {char ch;
		cin>>ch;
		A[3][j][1]=id (CH);
		cin>>ch;
	A[3][j][2]=id (CH);
		} for (j=1;j<=g;j++) {char ch;
		cin>>ch;
		A[4][j][1]=id (CH);
		cin>>ch;
	A[4][j][2]=id (CH);
	} cin>>s;
	Len=s.length ();
	for (i=0;i<len;i++) {oi[i+1]=id (s[i]);
			} for (i=1;i<=4;i++) {if (DP (1,len,i)) {cout<<p[i];
		Flag=true;
}} if (Flag==false) puts ("The name is wrong!"); }


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.