今天想了一天这到底什么小
结果回来答案看一看
靠北是要照顺序放上书架ㄛ==
干我还以为是不照顺序的
超级姆咪
不过我还是写很丑
index超乱
不知道怎么整理 一生就这样了
def minHeightShelves(self, books: List[List[int]], shelfWidth: int) -> int:
dp = [0 for _ in range(len(books)+1)]
for i in range(1, len(books)+1):
cur_th = books[i-1][0]
cur_h = books[i-1][1]
dp[i] = dp[i-1] + cur_h
for j in range(i-1, -1, -1):
cur_th += books[j-1][0]
if cur_th > shelfWidth:
break
cur_h = max(cur_h, books[j-1][1])
dp[i] = min(dp[i], cur_h+dp[j-1])
return dp[len(books)]