枚举每个元素,取还是不取
class Solution { public: void dfs(vector<vector<int> >& ans , vector<int>& s , vector<int>& tmp , int n , int dep) { ans.push_back(tmp); for(int i = dep ; i < n ; ++i) { tmp.push_back(s[i]); dfs(ans , s, tmp , n , i+1); tmp.pop_back(); } } vector<vector<int> > subsets(vector<int> &S) { vector<vector<int> >ans; if(S.size() < 0) return ans; vector<int> tmp; sort(S.begin() , S.end()); dfs(ans , S , tmp , S.size() , 0); return ans; } };