<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 Answer {
public:
    int len;
    int cnt;

    Answer(int len, int cnt) {
        this -> cnt = cnt;
        this -> len = len;
    }
};

class Solution {

    Answer solve(vector<int> &nums, int idx, vector<Answer> &dp) {
        if (idx < 0) {
            Answer answer(0, 1);
            return answer;
        }

        if (dp[idx].len != -1) {
            return dp[idx];
        }

        int len = 1, cnt = 1;
        for (int i = 0; i < idx; i++) {
            if (nums[i] < nums[idx]) {
                Answer temp = solve(nums, i, dp);
                int tempLen = temp.len + 1;
                if (tempLen > len) {
                    len = tempLen;
                    cnt = temp.cnt;
                } else if (tempLen == len) {
                    cnt += temp.cnt;
                }
            }
        }
        
        return dp[idx] = *(new Answer(len, cnt));
    }

public:
    int findNumberOfLIS(vector<int>& nums) {
        vector<Answer> dp(nums.size(),  *(new Answer(-1, -1)));

        int cnt = 0, len = 0;
        for (int i = 0; i < nums.size(); i++) {
            Answer answer = solve(nums, i, dp);
            if (answer.len > len) {
                len = answer.len;
                cnt = answer.cnt;
            } else if (answer.len == len) {
                cnt += answer.cnt;
            }
        }

        return cnt;
    }
};

/*
1 2 3 5 7
1 2 4 5 7
1 2 3 4 7
*/
16900