-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCountLIS.cpp
More file actions
33 lines (33 loc) · 814 Bytes
/
CountLIS.cpp
File metadata and controls
33 lines (33 loc) · 814 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
32
33
class Solution {
public:
int findNumberOfLIS(vector<int>& nums) {
int i,n=nums.size(),j,con=0,maxi=1;
vector<int>DP(n+1,1);
vector<int>COUNT(n+1,1);
for(i=1;i<n;i++)
{
for(j=0;j<i;j++)
{
if(nums[i]>nums[j])
{
if(DP[i]<DP[j]+1)
{
DP[i]=DP[j]+1;
COUNT[i]=COUNT[j];
}
else if(DP[i]==DP[j]+1)
{
COUNT[i]+=COUNT[j];
}
}
}
maxi=max(maxi,DP[i]);
}
for(i=0;i<n;i++)
{
if(DP[i]==maxi)
con+=COUNT[i];
}
return con;
}
};