human
What is a code to maximum sum from three arrays such that picking elements consecutively from same is not allowed and the other steps required given the following:
Maximum sum from three arrays such that picking elements consecutively from same is not allowed | Function to return the maximum sum.
Base case.
Already visited.
If the element has been taken from first array in previous step.
If the element has been taken from second array in previous step.
If the element has been taken from third array in previous step.
Driver code.
Pick element from first array.
Pick element from second array.
Pick element from third array.
Print the maximum of them"
How can the above be solved in Python?
assistant
#Here is code to maximum sum from three arrays such that picking elements consecutively from same is not allowed and the other steps required.
 def FindMaximumSum ( ind , kon , a , b , c , n , dp ) :
	if ind == n :
		return 0
	if dp [ ind ] [ kon ] != - 1 :
		return dp [ ind ] [ kon ]
	ans = - 10 ** 9 + 5
	if kon == 0 :
		ans = max ( ans , b [ ind ] + FindMaximumSum ( ind + 1 , 1 , a , b , c , n , dp ) )
		ans = max ( ans , c [ ind ] + FindMaximumSum ( ind + 1 , 2 , a , b , c , n , dp ) )
	elif kon == 1 :
		ans = max ( ans , a [ ind ] + FindMaximumSum ( ind + 1 , 0 , a , b , c , n , dp ) )
		ans = max ( ans , c [ ind ] + FindMaximumSum ( ind + 1 , 2 , a , b , c , n , dp ) )
	elif kon == 2 :
		ans = max ( ans , a [ ind ] + FindMaximumSum ( ind + 1 , 1 , a , b , c , n , dp ) )
		ans = max ( ans , b [ ind ] + FindMaximumSum ( ind + 1 , 0 , a , b , c , n , dp ) )
	dp [ ind ] [ kon ] = ans
	return ans
if __name__ == " _ _ main _ _ " :
	N = 3
	a = [ 6 , 8 , 2 , 7 , 4 , 2 , 7 ]
	b = [ 7 , 8 , 5 , 8 , 6 , 3 , 5 ]
	c = [ 8 , 3 , 2 , 6 , 8 , 4 , 1 ]
	n = len ( a )
	dp = [ [ - 1 for i in range ( N ) ] for j in range ( n ) ]
	x = FindMaximumSum ( 0 , 0 , a , b , c , n , dp )
	y = FindMaximumSum ( 0 , 1 , a , b , c , n , dp )
	z = FindMaximumSum ( 0 , 2 , a , b , c , n , dp )
	print ( max ( x , y , z ) )