Maximum score assigned to a subsequence of numerically consecutive and distinct array elements | ''Function to find the maximum score possible ; '' Base Case ; '' If previously occurred  subproblem occurred ; '' Check if lastpicked element differs  by 1 from the current element ; '' Calculate score by including  the current element ; '' Calculate score by excluding  the current element ; '' Return maximum score from  the two possibilities ; ''Function to print maximum score ; '' DP array to store results ; '' Function call ; ''Driver Code ; '' Given arrays ; '' Function Call
def maximumSum ( a , b , n , index , lastpicked , dp ) : NEW_LINE INDENT if ( index == n ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( dp [ index ] [ lastpicked + 1 ] != - 1 ) : NEW_LINE INDENT return dp [ index ] [ lastpicked + 1 ] NEW_LINE DEDENT option1 , option2 = 0 , 0 NEW_LINE if ( lastpicked == - 1 or a [ lastpicked ] != a [ index ] ) : NEW_LINE INDENT option1 = ( b [ index ] + maximumSum ( a , b , n , index + 1 , index , dp ) ) NEW_LINE DEDENT option2 = maximumSum ( a , b , n , index + 1 , lastpicked , dp ) NEW_LINE dp [ index ] [ lastpicked + 1 ] = max ( option1 , option2 ) NEW_LINE return dp [ index ] [ lastpicked + 1 ] NEW_LINE DEDENT def maximumPoints ( arr , brr , n ) : NEW_LINE INDENT index = 0 NEW_LINE lastPicked = - 1 NEW_LINE dp = [ [ - 1 for x in range ( n + 5 ) ] for y in range ( n + 5 ) ] NEW_LINE print ( maximumSum ( arr , brr , n , index , lastPicked , dp ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 3 , 3 , 1 ] NEW_LINE brr = [ - 1 , 2 , 10 , 20 , - 10 , - 9 ] NEW_LINE N = len ( arr ) NEW_LINE maximumPoints ( arr , brr , N ) NEW_LINE DEDENT