String Transformation

4

4 votes
Dynamic Programming, 2D dynamic programming, Algorithms
Problem

It is known that the string  contains only lowercase English characters. Also, the string contains lowercase English characters and digit characters. You can replace each digit character of by a substring consisting of lowercase English characters. Note that the length of such a substring should be not greater than the digit value.

For example, if string = “”, then you can replace the two “”’s by “” and “”, respectively. So  can be transformed into “”. 

Determine if the string can be transformed into the string  or not.

Note

The lengths of the string and are and , respectively.

Constraints

Input Format

  • The first line contains a single integer —- the number of test cases.
  • For each testcase:
    • The first line contains two integers ,  —- the lengths of and , respectively.

    • The second line contains a string of length .

    • The third line contains a string of length .

Output Format

  • For each Testcase, output "YES" if the string can be transformed into the string . Otherwise, output "NO".

 

Time Limit: 2.5
Memory Limit: 256
Source Limit:
Explanation

In the first testcase, you can replace the digit character "" of  by "", because the length of "" is less than .

In the second testcase, there is no way to transform the string  into .

Editor Image

?