leetcode1014】的更多相关文章

Given an array A of positive integers, A[i] represents the value of the i-th sightseeing spot, and two sightseeing spots i and j have distance j - i between them. The score of a pair (i < j) of sightseeing spots is (A[i] + A[j] + i - j) : the sum of…
这道题暴力算法,会超时: class Solution(object): def maxScoreSightseeingPair(self, A: 'List[int]') -> int: n = len(A) maxsum = 0 for i in range(n): for j in range(i+1,n): cursum = A[i] + A[j] + i - j maxsum = max(maxsum,cursum) return maxsum 因此,需要使用动态规划解决: class…