MoYi123
2020-10-27 15:49:56 +08:00
随便写了一个答案,应该是正解
def solution():
____a = [2, 3, 5, 7, 9]
____ret = []
____memo = set()
____def dp(index, acc):
________if (index, tuple(acc)) in memo:
____________return
________else:
____________memo.add((index, tuple(acc)))
________if index == 5:
____________return
________if sum(acc) == 13:
____________ret.append(tuple(acc))
________if sum(acc) >= 13:
____________return
________dp(index + 1, acc[:])
________dp(index, acc[:] + [a[index]])
____dp(0, [])
____return ret