human
Memoization ( 1D , 2D and 3D ) | Returns length of LCS for X [ 0. . m - 1 ] , Y [ 0. . n - 1 ] memoization applied in recursive solution.
base case.
if the same state has already been computed.
if equal , then we store the value of the function call.
store it in arr to avoid further repetitive work in future function calls.
store it in arr to avoid further repetitive work in future function calls.
Driver Code"
Solution in Python:
 ... Give me a code to memoization ( 1D , 2D and 3D ) and the other steps required?
assistant
#Here is code to memoization ( 1D , 2D and 3D ) and the other steps required.
 def lcs ( X , Y , Z , m , n , o ) :
	global arr
	if ( m == 0 or n == 0 or o == 0 ) :
		return 0
	if ( arr [ m - 1 ] [ n - 1 ] [ o - 1 ] != - 1 ) :
		return arr [ m - 1 ] [ n - 1 ] [ o - 1 ]
	if ( X [ m - 1 ] == Y [ n - 1 ] and Y [ n - 1 ] == Z [ o - 1 ] ) :
		arr [ m - 1 ] [ n - 1 ] [ o - 1 ] = 1 + lcs ( X , Y , Z , m - 1 , n - 1 , o - 1 )
		return arr [ m - 1 ] [ n - 1 ] [ o - 1 ]
	else :
		arr [ m - 1 ] [ n - 1 ] [ o - 1 ] = max ( lcs ( X , Y , Z , m , n - 1 , o ) , max ( lcs ( X , Y , Z , m - 1 , n , o ) , lcs ( X , Y , Z , m , n , o - 1 ) ) )
		return arr [ m - 1 ] [ n - 1 ] [ o - 1 ]
arr = [ [ [ 0 for k in range ( 100 ) ] for j in range ( 100 ) ] for i in range ( 100 ) ]
for i in range ( 100 ) :
	for j in range ( 100 ) :
		for k in range ( 100 ) :
			arr [ i ] [ j ] [ k ] = - 1
X = " geeks "
Y = " geeksfor "
Z = " geeksforgeeks "
m = len ( X )
n = len ( Y )
o = len ( Z )
print ( " Length ▁ of ▁ LCS ▁ is ▁ " , lcs ( X , Y , Z , m , n , o ) )