MBLAST - BLAST
There are given two strings, A and B. An expansion of some string X is a string created by adding or inserting any number (zero, one or more) of blanks anywhere in the string, or in the begining or the end of the string. Eg., if the string X is ‘abcbcd’, then the strings 'abcb-cd', '-a-bcbcd-' and 'abcb-cd-' are expansions of the string X (blanks are denoted by the character ‘-‘).
If A1 is an expansion of the string A, and B1 is and expansion of the string B, and if A1 and B1 are of the same length, then we define the distance of the strings A1 and B1 as the sum of the distances of the characters on the same positions in these strings. We define the distance of two characters as the absolute difference of their ASCII codes, except the distance of the blank and another character, which is given (and equal for all characters).
You are to write a program which finds the expansions A1 and B1 of strings A and B, that have the smallest difference.
The first line of the input file consists of the string A, and the second line of string B. They are consisted only of lower case characters of the english alphabet (a-z), and the number of characters in any of the strings is less than or equal to 2000.
The third line consists of an integer K, 1 ≤ K ≤ 100, the distance of the blank and the other characters.
The first only line of the input file should consist of the smallest distance as defined in the text of the task.
Input: cmc snmn 2 output: 10
Input: koiv ua 1 output: 5
input: mj jao 4 output: 12
substr causes tle,
Great! ACed it in one go!!
Got AC by Top-down + memoization . Based on LCS algorithm Edit Distance problem .., properly understand them first. Here, is a very good explanation : https://youtu.be/Qf5R-uYQRPk?t=8.
top-down ac.... :)
tle in topdown but ac in iterative
showing tle in bottom up manner. how to optimize help! @up79
who said bottom up is not passing ?
Last edit: 2016-10-20 16:50:57
tle in top down but ac int bottom up :)
AC in one go !!!