[Python] dp bitmask + two-sum solution
Idea\n\nWe  know how to find all possible subset sums of an array (bitmask or dfs). We also know to find the two sum closest to target (sort and two-pointer). S
**Idea**\n\nWe  know how to find all possible subset sums of an array (bitmask or dfs). We also know to find the two sum closest to target (sort and two-pointer). Solving these two sub-problem will lead us to the solution.\n\n\n</br>\n\n**Complexity**\n\n- Time complexity: `O(NlogN + M*2^(2M))`\n- Space complexity: `O(2^(2M))`\n\n</br>\n\n**Python**\n\n```Python\nclass Solution:\n    def closestCost(self, A: List[int], B: List[int], target: int) -> int:\n        # find all possible sums\n        B *= 2\n        dp = [0] * (1 << len(B))\n        for i in range(len(B)):\n            for mask in range(1 << i):\n                dp[mask | (1 << i)] = dp[mask] + B[i]\n        \n        # sort and dedup\n        A.sort()\n        dp = sorted(list(set(dp)))\n        \n        # find closest two-sum \n        ans = A[0]\n        i, j = 0, len(dp) - 1\n        while i < len(A) and j >= 0:\n            cur = A[i] + dp[j]\n            ans = min(ans, cur, key=lambda x: (abs(x-target), x))\n            if cur < target: i += 1\n            elif cur > target: j -= 1\n            else: return target\n        return ans\n```
[]