Python | dfs + pruning
\n    def closestCost(self, baseCosts: List[int], toppingCosts: List[int], target: int) -> int:\n        self.ans = float(\'inf\')\n        self.minval = float(
```\n    def closestCost(self, baseCosts: List[int], toppingCosts: List[int], target: int) -> int:\n        self.ans = float(\'inf\')\n        self.minval = float(\'inf\')\n        for base in baseCosts:\n            self.dfs(toppingCosts, target, 0, base)\n        return self.ans\n    \n    def dfs(self, toppingCosts, target, start, cur):\n        if start == len(toppingCosts) or cur > target:\n            if abs(cur - target) < self.minval:\n                self.minval = abs(cur - target) \n                self.ans = cur\n            elif abs(cur - target) == self.minval:\n                self.ans = min(self.ans, cur)\n            return \n            \n       \n        for i in range(3):\n            self.dfs(toppingCosts, target, start+1, cur+i*toppingCosts[start])\n```
['Recursion']