// 既然不能重复利用,就在递归中选择下一个数,不能重复的话,就用set class Solution {public: vector> combinationSum2(vector & candidates, int target) { set > res; sort(candidates.begin(),candidates.end()); vector add; DFS(candidates,target,0,add,res); return vector >(res.begin(),res.end()); } void DFS(vector & candidates, int target,int start,vector & add,set >& res){ if(target < 0)return; else if(target == 0){res.insert(add);} else{ for(int i=start;i < candidates.size();i++){ add.push_back(candidates[i]); DFS(candidates,target-candidates[i],i+1,add,res); add.pop_back(); } } }};