<p>Given an integer array&nbsp;<code>nums</code>, return <em>the number of longest increasing subsequences.</em></p>

<p><strong>Notice</strong> that the sequence has to be <strong>strictly</strong> increasing.</p>

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

<pre>
<strong>Input:</strong> nums = [1,3,5,4,7]
<strong>Output:</strong> 2
<strong>Explanation:</strong> The two longest increasing subsequences are [1, 3, 4, 7] and [1, 3, 5, 7].
</pre>

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

<pre>
<strong>Input:</strong> nums = [2,2,2,2,2]
<strong>Output:</strong> 5
<strong>Explanation:</strong> The length of the longest increasing subsequence is 1, and there are 5 increasing subsequences of length 1, so output 5.
</pre>

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

<ul>
	<li><code>1 &lt;= nums.length &lt;= 2000</code></li>
	<li><code>-10<sup>6</sup> &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
	<li>The answer is guaranteed to fit inside a 32-bit integer.</li>
</ul>

class Solution {
    private:
    int count(int index,int ans,vector<int>&dp,vector<int>& nums,
    vector<int>&counts){
        if(ans == 1)
        return 1;
        
        if(counts[index] != -1)
        return counts[index];
        int temp=0;
        for(int i=index-1;i>=0;i--){
            if(nums[i] < nums[index] && dp[i]+1 == dp[index])
            temp+=counts[i]=count(i,dp[i],dp,nums,counts);
        }
        return temp;
    }
public:
    int findNumberOfLIS(vector<int>& nums) {
        int n=nums.size();
        vector<int>dp(n,1);
        int ans=1;

        for(int i=1;i<n;i++){
            for(int j=0;j<i;j++){
                if(nums[j] < nums[i])
                dp[i]=max(dp[i],1+dp[j]);
            }
            ans=max(ans,dp[i]);
        }
        int temp=0;
        vector<int>counts(n,-1);
        for(int i=n-1;i>=0;i--){
            if(dp[i] == ans)
            temp+=count(i,ans,dp,nums,counts);
        }
        return temp;
    }
};
16400