Note:

1. To maximized the gap, A[i-1] will be eithor floor (1) or ceiling (B[i-1]).

2. Focus on 2 possibilities with A[i] (floor 1 or ceiling B[i]) and their possible preceedings (previous sum with floor or ceiling)

def cost(B):
top, bottom = 0, 0
for i in range(1, len(B)):
t = max(top + abs(B[i] - B[i-1]), bottom + abs(B[i] - 1))
b = max(top + abs(B[i-1] -1), bottom)
top, bottom = t, b
return max(top, bottom)
 
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 g0d2 的頭像
    g0d2

    kazi1@的部落格

    g0d2 發表在 痞客邦 留言(0) 人氣()