human
Give me a code to minimum cost to make two strings identical by deleting the digits and the other steps required given the following:
Minimum cost to make two strings identical by deleting the digits | Function to returns cost of removing the identical characters in LCS for X [ 0. . m - 1 ] , Y [ 0. . n - 1 ].
Following steps build L [ m + 1 ] [ n + 1 ] in bottom up fashion . Note that L [ i ] [ j ] contains cost of removing identical characters in LCS of X [ 0. . i - 1 ] and Y [ 0. . j - 1 ].
If both characters are same , add both of them.
Otherwise find the maximum cost among them.
Returns cost of making X [ ] and Y [ ] identical.
Find LCS of X [ ] and Y [ ].
Initialize the cost variable.
Find cost of all acters in both strings.
Driver program to test above function"
Solution in Python:
assistant
#Here is code to minimum cost to make two strings identical by deleting the digits and the other steps required.
 def lcs ( X , Y , m , n ) :
	L = [ [ 0 for i in range ( n + 1 ) ] for i in range ( m + 1 ) ]
	for i in range ( m + 1 ) :
		for j in range ( n + 1 ) :
			if ( i == 0 or j == 0 ) :
				L [ i ] [ j ] = 0
			elif ( X [ i - 1 ] == Y [ j - 1 ] ) :
				L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 2 * ( ord ( X [ i - 1 ] ) - 48 )
			else :
				L [ i ] [ j ] = max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] )
	return L [ m ] [ n ]
def findMinCost ( X , Y ) :
	m = len ( X )
	n = len ( Y )
	cost = 0
	for i in range ( m ) :
		cost += ord ( X [ i ] ) - 48
	for i in range ( n ) :
		cost += ord ( Y [ i ] ) - 48
	ans = cost - lcs ( X , Y , m , n )
	return ans
X = "3759"
Y = "9350"
print ( " Minimum ▁ Cost ▁ to ▁ make ▁ two ▁ strings ▁ " , " identical ▁ is ▁ = ▁ " , findMinCost ( X , Y ) )