class Solution {
public:
vector<vector<int>> findSubsequences(vector<int>& nums) {
set<vector<int>> st;//用 set 保存结果去重复
vector<int> cur;//当前子序列
dfs(st,cur,nums,0);
vector<vector<int>> res(st.begin(),st.end());
return res;
}
void dfs(set<vector<int>> &st, vector<int> &cur,vector<int>& nums,int curIndex )
{
if( curIndex >= nums.size() ) //超边界,没元素可选
{
//判断当前子序列
if( cur.size() > 1)
st.insert(cur);
return;
}
//遍历当前所有可能的选择:选择curIndex 、不选curIndex
//选择curIndex
if( cur.size() == 0 || nums[curIndex] >= cur.back())
{
cur.push_back(nums[curIndex]);//可以加入序列
dfs( st,cur,nums,curIndex+1);
cur.pop_back();//撤销选择
}
//不选curIndex
dfs( st,cur,nums,curIndex+1);
}
};