A regular expression is used to describe a set of strings. For this problem the alphabet is limited to 'a' and 'b'. R is a regular expression if:
The set of strings recognised by R are as follows:
The edit distance between two strings s1 and s2 is the minimum number of characters to be inserted/deleted or replaced in s1 to make it equal to s2.
Given two regular expressions R1 and R2, find the minimum edit distance amongst all pairs of strings s1 and s2 such that s1 is recognised by R1 and s2 is recognised by R2.
The first line contains the number of test cases T. T test cases follow.
Each test case contains two lines containing two regular expressions R1 and R2. There is a blank line after each test case.
T <= 85
1 <= length(R1), length(R2) <= 65
You are guaranteed that R1 and R2 will conform to the definition provided above.
Output T lines one corresponding to each test case containing the required answer for the corresponding test case.
2 ((a|b)*) (a(b(aa))) (a((ab)*)) (a(b(((ab)b)b)))
0 2
For the first case R1 recognises all strings over the alphabet a and b. Thus it recognises the string "abaa" which is also recognised by R2.
For the second case the strings "aababab" and "ababbb" are recognised by R1 and R2 respectively and have edit distance of 2.
Migrated from old NTUJ.
Regional Amritapuri 2010
No. | Testdata Range | Score |
---|