Edit Distance Yet Again
Time limit20sMemory limit512 MB
Decide whether the edit distance between two strings is at most k, and if so, output a minimum-length sequence of insert, delete, and replace operations.
- Level
Hard8 of 10
- Topics
- String, Dynamic programming, String matching
- Solved
- No attempts yet
Problem
Have you ever heard of the edit distance problem? Given two strings of lowercase English letters, you must determine the minimum number of operations needed to transform the first one into the second one. A single operation can be one of the following:
- inserting a character into the sequence at any position,
- deleting any character from the sequence,
- substituting a character with another one.
Everyone at our university loves this problem, maybe a little too much, so we decided to create an easier one! You are given two strings and , and an integer . Find out whether the edit distance between the strings is at most . If so, you must also output any sequence of the minimum possible number of operations that transforms the first string into the second one.
Input
The first line contains the number of test cases (). The descriptions of the test cases follow.
The first line of each test case contains three integers (, ), the lengths of the strings and the parameter from the problem. The second line contains a string of length consisting of lowercase English letters, the string . The third line contains a string of length consisting of lowercase English letters, the string .
The total length of all strings in all test cases does not exceed .
Output
For each test case, if the edit distance is greater than , print a single line containing NO. Otherwise, print YES on the first line. On the second line, print the minimum number of operations needed to transform into . Then print the operations, one per line.
- To insert a lowercase English letter into a sequence of size at position (), print
INSERT p c. - To delete the character at position of a sequence of size (), print
DELETE p. - To substitute the character at position of a sequence of size () with a lowercase English letter , print
REPLACE p c.