human
Treasure and Cities | k is current index and col is previous color ..
base case.
check if color of this city is equal to prev visited city.
return max of both options.
Driver Code.
Initially begin with color 0"
Solution in Python:
assistant
#Here is code to treasure and Cities and the other steps required.
 def MaxProfit ( treasure , color , n , k , col , A , B ) :
	sum = 0
	if k == n :
		return 0
	if col == color [ k ] :
		sum += max ( A * treasure [ k ] + MaxProfit ( treasure , color , n , k + 1 , color [ k ] , A , B ) , MaxProfit ( treasure , color , n , k + 1 , col , A , B ) )
	else :
		sum += max ( B * treasure [ k ] + MaxProfit ( treasure , color , n , k + 1 , color [ k ] , A , B ) , MaxProfit ( treasure , color , n , k + 1 , col , A , B ) )
	return sum
A = - 5
B = 7
treasure = [ 4 , 8 , 2 , 9 ]
color = [ 2 , 2 , 6 , 2 ]
n = len ( color )
print ( MaxProfit ( treasure , color , n , 0 , 0 , A , B ) )