<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [4,6,7,7]
<strong>Output:</strong> [[4,6],[4,6,7],[4,6,7,7],[4,7],[4,7,7],[6,7],[6,7,7],[7,7]]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [4,4,3,2,1]
<strong>Output:</strong> [[4,4]]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 15</code></li>
	<li><code>-100 &lt;= nums[i] &lt;= 100</code></li>
</ul>

#include <iostream>
#include <vector>
#include <set>

using namespace std;

class Solution {
public:
    vector<vector<int>> findSubsequences(vector<int>& nums) {
        vector<vector<int>> dp[nums.size()];  // DP array to store subsequences ending at each element
        set<vector<int>> res;  // Set to store unique subsequences
        
        for (int i = 0; i < nums.size(); ++i) {
            for (int j = 0; j < i; ++j) {
                if (nums[j] <= nums[i]) {
                    // For each subsequence ending at nums[j], we can append nums[i]
                    for (const auto& subseq : dp[j]) {
                        vector<int> newSubseq = subseq;
                        newSubseq.push_back(nums[i]);
                        dp[i].push_back(newSubseq);
                        res.insert(newSubseq);  // Insert into result set
                    }
                }
            }
            // Single element subsequence starting with nums[i]
            dp[i].push_back({nums[i]});
        }
        
        // Add subsequences of length >= 2 to the result
        for (int i = 0; i < nums.size(); ++i) {
            for (const auto& subseq : dp[i]) {
                if (subseq.size() > 1) {
                    res.insert(subseq);
                }
            }
        }
        
        return vector<vector<int>>(res.begin(), res.end());  // Convert set to vector of vectors
    }
};


43378