标签:div lse style bsp after erp class max partition
又是一道dp的题目,还是给出一个超时的解。
1 class Solution: 2 def maxSumAfterPartitioning(self, A: ‘List[int]‘, K: int) -> int: 3 n = len(A) 4 dp = [0] * (n+1) 5 for i in range(n+1): 6 curmax = 0 7 for j in range(1,K+1): 8 if i-j>=0: 9 last = dp[i-j] 10 cur = max(A[i-j:i])*j 11 curmax = max(curmax,last+cur) 12 else: 13 break 14 dp[i] = curmax 15 return dp[n]
标签:div lse style bsp after erp class max partition
原文地址:https://www.cnblogs.com/asenyang/p/10924997.html