HDU1501 记忆化搜索

来源:互联网 发布:gal gadot 知乎 编辑:程序博客网 时间:2024/04/29 12:44

Zipper

Time Limit: 2000/1000 MS(Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2108    Accepted Submission(s): 752

Problem Description

Given three strings, you are to determine whether thethird string can be formed by combining the characters in the first twostrings. The first two strings can be mixed arbitrarily, but each must stay inits original order.

For example, consider forming "tcraete" from "cat" and"tree":

String A: cat
String B: tree
String C: tcraete


As you can see, we can form the third string by alternating characters from thetwo strings. As a second example, consider forming "catrtee" from"cat" and "tree":

String A: cat
String B: tree
String C: catrtee


Finally, notice that it is impossible to form "cttaree" from"cat" and "tree".

 

 

Input

The first line ofinput contains a single positive integer from 1 through 1000. It represents thenumber of data sets to follow. The processing for each data set is identical.The data sets appear on the following lines, one data set per line.

For each data set, the line of input consists of three strings, separated by asingle space. All strings are composed of upper and lower case letters only.The length of the third string is always the sum of the lengths of the firsttwo strings. The first two strings will have lengths between 1 and 200characters, inclusive.

 

 

Output

For each data set, print:

Data set n: yes

if the third string can be formed from the first two, or

Data set n: no

if it cannot. Of course n should be replaced by the data set number. See thesample output below for an example.

 

 

Sample Input

3

cat tree tcraete

cat tree catrtee

cat tree cttaree

 

 

Sample Output

Data set 1: yes

Data set 2: yes

Data set 3: no

 

记忆化搜索,一开始没看出来,一直DP搞了好久……