class Solution:
def divingBoard(self, shorter: int, longer: int, k: int) -> List[int]:
if k == 0:
return []
if shorter == longer:
return [shorter * k]
res = []
seen = set()
def func(remains, current, count_s, count_l):
if remains == 0:
res.append(current)
return
if (count_s + 1, count_l) not in seen: # 注意剪枝
seen.add((count_s + 1, count_l))
func(remains - 1, current + shorter, count_s + 1, count_l)
if (count_s, count_l + 1) not in seen:
seen.add((count_s, count_l + 1))
func(remains - 1, current + longer, count_s, count_l + 1)
func(k, 0, 0, 0)
return res