Banner Repair
Time limit10sMemory limit128 MB
Transform one uppercase banner string into another with block insertions and deletions where each block of length S costs X plus S times Y.
- Level
Medium7 of 10
- Topics
- Dynamic programming, String
- Solved
- No attempts yet
Problem
The great crocheting festival held every year is approaching. Mr. Wincenty, who is skilled at crocheting, decided to help out his neighbors by crocheting a banner that advertises the festival. Unfortunately, he made a large mistake in the text he crocheted onto it.
His son Witek wants to help his father fix the banner. To repair it he may use only the following two operations.
- Deletion: erase one run of consecutive letters from the banner.
- Insertion: place one run of letters at the very beginning, at the very end, or between two letters of the banner.
Each operation takes minutes, where is the length of the run of letters inserted or deleted in that operation. Find the minimum total time needed to turn the initial banner text into the target banner text.
Input
The first line contains the number of test cases . The descriptions of the test cases follow.
Each test case consists of three lines.
- Line 1: an integer and a string . is the initial banner text and is its length ().
- Line 2: an integer and a string in the same format, where is the target banner text.
- Line 3: two real numbers and , each given with up to 6 digits after the decimal point ().
Both and consist only of uppercase English letters.
Output
For each test case, print the minimum repair time on its own line, with 6 digits after the decimal point.