class Solution {

public:

vector<vector<int>> re;

vector<int> t;

```
void subs(vector<int> &S,int depth,int maxD,int s)
{
if (depth == maxD)
{
re.push_back(t);
return;
}
for (int i = s;i<S.size();i++)
{
t[depth] = S[i];
subs(S,depth+1,maxD,i+1);
}
}
vector<vector<int> > subsets(vector<int> &S) {
re.clear();
re.push_back(t);
sort(S.begin(),S.end()); //must be sorted
for (int i = 0;i<S.size();i++)
{
t.resize(i+1);
subs(S,0,i+1,0);
}
return re;
}
```

};