[Java][Recursion]
\nclass Solution {\n    public int closestCost(int[] baseCosts, int[] toppingCosts, int target) {\n        List<Integer> tc = new ArrayList();\n        dfs(topp
```\nclass Solution {\n    public int closestCost(int[] baseCosts, int[] toppingCosts, int target) {\n        List<Integer> tc = new ArrayList();\n        dfs(toppingCosts, 0, 0, tc);\n        int minD = 10000000;\n        int ans = 0;\n        for(int i: baseCosts){\n            for(Integer cost: tc){\n                int val = Math.abs(i + cost - target);\n                if(val < minD){\n                    minD = val;\n                    ans = i+cost;\n                }else if(val == minD){\n                    if(i+cost < ans){\n                        ans = i+cost;\n                    }\n                }\n            }\n        }\n        return ans;\n    }\n    \n    void dfs(int []toppingCosts, int ind, int amount, List<Integer> tc){\n        if(ind == toppingCosts.length){\n            tc.add(amount);\n            return ;\n        }\n        dfs(toppingCosts, ind+1, amount, tc);\n        dfs(toppingCosts, ind+1, amount+toppingCosts[ind], tc);\n        dfs(toppingCosts, ind+1, amount+2*toppingCosts[ind], tc);\n    }\n}\n```
[]