标签:return solution col ali max lse span obj inf
题目描述:
方法:从后向前dp
class Solution(object): def stoneGameIII(self, A): n = len(A) dp = [-float(‘inf‘)] * n for i in range(n-1,-1,-1): dp[i] = max(dp[i], sum(A[i:i+1]) - (dp[i+1] if i+1<n else 0)) dp[i] = max(dp[i], sum(A[i:i+2]) - (dp[i+2] if i+2<n else 0)) dp[i] = max(dp[i], sum(A[i:i+3]) - (dp[i+3] if i+3<n else 0)) if dp[0] == 0:return "Tie" if dp[0] > 0:return "Alice" if dp[0] < 0:return "Bob"
标签:return solution col ali max lse span obj inf
原文地址:https://www.cnblogs.com/oldby/p/12638661.html