String Transformation
Practice
4 (4 votes)
Dynamic programming
2d dynamic programming
Algorithms
Problem
82% Success 1220 Attempts 30 Points 2.5s Time Limit 256MB Memory 1024 KB Max Code

It is known that the string \(s\) contains only lowercase English characters. Also, the string \(t\) contains lowercase English characters and digit characters. You can replace each digit character of \(t\) 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 \(t\) = “\(a22fg\)”, then you can replace the two “\(2\)”’s by “\(bc\)” and “\(de\)”, respectively. So \(t\) can be transformed into “\(abcdefg\)”. 

Determine if the string \(t\) can be transformed into the string \(s\) or not.

Note

The lengths of the string \(s\) and \(t\) are \(n\) and \(m\), respectively.

Constraints

  • \(1 \leq T \leq 1000\)
  • \(1 \leq n \leq 1000\)
  • \(1 \leq m \leq 1000\)

Input Format

  • The first line contains a single integer \(T\) —- the number of test cases.
  • For each testcase:
    • The first line contains two integers \(n\), \(m\) —- the lengths of \(s\) and \(t\), respectively.

    • The second line contains a string \(s\) of length \(n\).

    • The third line contains a string \(t\) of length \(m\).

Output Format

  • For each Testcase, output "YES" if the string \(t\) can be transformed into the string \(s\). Otherwise, output "NO".

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
5 votes
Tags:
AlgorithmsDynamic Programming2D dynamic programmingC++
Points:30
9 votes
Tags:
Dynamic ProgrammingAlgorithms2D dynamic programmingData Structures
Points:30
1 votes
Tags:
Dynamic Programming2D dynamic programmingAlgorithms