#include <vector>
class Solution {
public:
void dfs(vector<vector<int>> & ans, vector<int> temp, vector<int> S, int start,int l){
if(l == temp.size()) {
ans.push_back(temp);
return;
}
for(int i = start; i < S.size(); i ++){
temp.push_back(S[i]);
dfs(ans, temp, S, i + 1, l);
temp.pop_back();
}
return;
}
vector<vector<int> > subsets(vector<int>& S) {
vector<vector<int>> ans;
vector<int> temp;
ans.push_back(temp);
for(int i = 1; i <= S.size(); i ++ ){
dfs(ans, temp, S, 0, i);//这个代码相当于是每一层一个for,第几层就会有几个元素
}
return ans;
}
};