OverlappingConcatenation
TCO10 Round 5 · 2010-04-11 · by StevieT
Problem Statement
Assuming that each unknown character will be selected uniformly at random from the characters contained in alphabet, return the expected length of the shortest overlapping concatenation of A and B.
Constraints
- alphabet will contain between 1 and 26 lowercase letters ('a' - 'z'), inclusive.
- The characters in alphabet will be distinct.
- A and B will contain between 1 and 32 characters, inclusive.
- A and B will contain the same number of characters.
- Each character in A and B will either be contained in alphabet or it will be '*'.
"aa*aa" "a*aaa" "ab" Returns: 7.0
The 4 equal-probability possibilities for the shortest overlapping concatenation (SOC) are as follows: A | B | SOC aaaaa | aaaaa | aaaaa aabaa | aaaaa | aabaaaaa aaaaa | abaaa | aaaaabaaa aabaa | abaaa | aabaaa The result is therefore (5 + 8 + 9 + 6) / 4 = 7.
"**" "**" "ab" Returns: 3.125
There are 16 possibilities for A and B. Of these, 4 give a SOC of length 2; 6 give a SOC of length 3; and 6 give a SOC of length 4. The answer is therefore (4*2 + 6*3 + 6*4) / 16 = 3.125.
"**a*cd" "cde***" "abcdefghijklmnopqrstuvwxyz" Returns: 10.0
It makes no difference what the unknown characters are; the SOC is always the same length.
"h*phz*" "hzph*p" "zph" Returns: 10.555555555555557
"a*a*a*a*a*a*" "*a*a*a*a*a*a" "abcdef" Returns: 23.6983063804134
Submissions are judged against all 133 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class OverlappingConcatenation with a public method double shortestExpected(string A, string B, string alphabet) · 133 test cases · 2 s / 256 MB per case