-
Notifications
You must be signed in to change notification settings - Fork 3
/
673.cpp
27 lines (26 loc) · 835 Bytes
/
673.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution {
public:
int findNumberOfLIS(vector<int>& nums) {
int n = nums.size();
vector<int> lenDP(n, 1);
vector<int> countDP(n, 1);
int maxLen = 1;
int counting = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (nums[i] <= nums[j]) continue;
if (lenDP[j] + 1 == lenDP[i]) countDP[i] += countDP[j];
else if (lenDP[j] + 1 > lenDP[i]) {
lenDP[i] = lenDP[j] + 1;
countDP[i] = countDP[j];
}
}
if (lenDP[i] == maxLen) counting += countDP[i];
else if (lenDP[i] > maxLen) {
maxLen = lenDP[i];
counting = countDP[i];
}
}
return counting;
}
};