class Solution {
private:
int cnt[30];
vector<vector<int>> res;
vector<int> path;
void dfs(int p) {
if (p > 10) {
res.push_back(path);
return;
}
for (int i = 0; i < cnt[p + 10] + 1; ++i) {
dfs(p + 1);
path.push_back(p);
}
for (int i = 0; i < cnt[p + 10] + 1; ++i) {
path.pop_back();
}
}
public:
vector<vector<int>> subsetsWithDup(vector<int>& nums) {
for (int i: nums) {
++cnt[i + 10];
}
dfs(-10);
return res;
}
};