今天想了一天這到底什麼小
結果回來答案看一看
靠北是要照順序放上書架ㄛ==
幹我還以為是不照順序的
超級姆咪
不過我還是寫很醜
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)]