-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path673.cpp
More file actions
31 lines (31 loc) · 878 Bytes
/
Copy path673.cpp
File metadata and controls
31 lines (31 loc) · 878 Bytes
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
28
29
30
31
class Solution {
public:
int findNumberOfLIS(vector<int> &nums) {
int n = nums.size();
if (n == 0)
return 0;
vector<int> dp(n, 1);
vector<int> len(n, 1);
int maxLength = 1;
for (int i = 1; i < n; ++i) {
int cnt = 0;
for (int j = 0; j < i; ++j) {
if (nums[i] > nums[j]) {
if (dp[i] < dp[j] + 1) {
dp[i] = dp[j] + 1;
cnt = 0;
}
}
if (dp[i] == dp[j] + 1)
cnt += len[j];
}
len[i] = max(len[i], cnt);
maxLength = max(maxLength, dp[i]);
}
int res = 0;
for (int i = n - 1; i >= 0; --i)
if (maxLength == dp[i])
res += len[i];
return res;
}
};