def dfs_stk(self, A, k, cur, remain, ret):
        if len(cur) == k and remain == 0:
            ret.append(list(cur))

        if not A or len(cur) >= k or len(A)+len(cur) < k:
            return

        # save space
        num = A.pop()

        self.dfs(A, k, cur, remain, ret)
        cur.append(num)
        self.dfs(A, k, cur, remain-num, ret)
        cur.pop()

        A.append(num)
self.dfs_stk(A[::-1], k, [], target, ret)
dataset/ETHPy150Open algorhythms/LintCode/k Sum II.py/Solution.dfs_stk