1def comb_sum(cands, target):
2 cands = sorted(cands)
3 res = []
4 path = []
5 def dfs(start, rem):
6 if rem == 0:
7 res.append(list(path))
8 return
9 for i in range(start, len(cands)):
10 c = cands[i]
11 if c > rem:
12 break
13 path.append(c)
14 dfs(i, rem - c)
15 path.pop()
16 dfs(0, target)
17 return res