Getting the max sum from the last column
ans = - 1 NEW_LINE for i in range ( 1 , m , 1 ) : NEW_LINE INDENT if ( dp [ i ] [ n ] ) : NEW_LINE INDENT ans = max ( ans , dp [ i ] [ n ] ) NEW_LINE DEDENT DEDENT return ans NEW_LINE