C++ Backtracking
\nclass Solution {\npublic:\n    void calculate(vector<int> &top,int target,int curr,int &ans,int index){\n        if(abs(curr-target)<abs(ans-target)){\n      
```\nclass Solution {\npublic:\n    void calculate(vector<int> &top,int target,int curr,int &ans,int index){\n        if(abs(curr-target)<abs(ans-target)){\n            ans=curr;\n        }\n        if(abs(curr-target)==abs(ans-target)){\n            ans=min(ans,curr);\n        }\n        //Adding curr>target+abs(ans-target) for optimization\n        if(index>=top.size() || curr>target+abs(ans-target))     \n            return;\n        calculate(top,target,curr,ans,index+1);\n        calculate(top,target,curr+top[index],ans,index+1);\n        calculate(top,target,curr+2*top[index],ans,index+1);\n    }\n    int closestCost(vector<int>& baseCosts, vector<int>& toppingCosts, int target) {\n        int ans=INT_MAX;\n        for(auto x:baseCosts){\n            calculate(toppingCosts,target,x,ans,0);\n        }\n        return ans;\n    }\n};\n```
['Backtracking', 'Depth-First Search', 'C', 'C++']