Backtracking(+memo) with comments
Pre-processing\nIn order to take care of the restriction of "You can add one or more types of topping or have no toppings at all."(add each topping at most twic
* Pre-processing\nIn order to take care of the restriction of "You can add one or more types of topping or have no toppings at all."(add each topping at most twice), I double the toppings list, so we are back to a more classic backtracking logic down below.\n* Backtracking. (See comments)\n\n```python\nclass Solution:\n    def closestCost(self, baseCosts: List[int], toppingCosts: List[int], target: int) -> int:\n        self.cost = baseCosts[0]\n        # my trick here: double the toppings list since each topping can only be used at most twice -- so I don\'t need to care about this restriction down the road\n        toppings = toppingCosts + toppingCosts\n\n        # toppingIdx: point to current topping\n        # used: cost of picked items (base + topping)\n        @lru_cache(None)\n        def dfs(toppingIdx, used):\n            # base case\n            if used > target:\n                # update if closer\n                if used - target < abs(self.cost - target):\n                    self.cost = used\n                # end here since used is already exceed target\n                return\n            # update if closer\n            if target - used <= abs(self.cost - target):\n                self.cost = used\n            # reach end of the topping list\n            if toppingIdx == len(toppings):\n                return\n            \n            # move onto next\n            # pick current item\n            dfs(toppingIdx+1, used+toppings[toppingIdx])\n            # skip current item\n            dfs(toppingIdx+1, used)\n\n        # try out different base\n        for base in baseCosts:\n            dfs(0, base)\n            \n        return self.cost\n```\n\n> **Time**: O(n * 2^m). Since we have the constrain m <= 10, shouldn\'t be too bad. Plus, we can use memoization to avoid calculating the duplicates.\n> **Space**: O(m), which is used to store the recursion stack.\n> (n == baseCosts.length, m == toppingCosts.length)
['Backtracking', 'Python', 'Python3']