class Solution {
public:
    vector<vector<int> > combinationSum2(vector<int> &num, int target) {
        vector<vector<int>> res;
        vector<int> path;
        sort(num.begin(), num.end());
        dfs(num, target, res, path, 0, 0);
        return res;
        
    }
    void dfs(vector<int> &num, int target, vector<vector<int>>& res,
            vector<int>& path, int cur_sum, int index){
        if(cur_sum==target){
            res.push_back(path);
            return;
        }// 剪枝 && 从index开始
        for(int i=index; i<num.size()&&num[i]+cur_sum <= target; i++){
            if(i>index && num[i]==num[i-1])
                continue;
            path.push_back(num[i]);
            cur_sum += num[i];
            dfs(num, target, res, path, cur_sum, i+1);
            cur_sum -= num[i];
            path.pop_back();
            
        }
    }
};