其他分享
首页 > 其他分享> > Leetcode-673 (Number of Longest Increasing Subsequence)最长递增子序列的个数

Leetcode-673 (Number of Longest Increasing Subsequence)最长递增子序列的个数

作者:互联网

 1 #define _for(i,a,b) for(int i = (a);i < (b);i ++)
 2 class Solution
 3 {
 4     public:
 5         int findNumberOfLIS(vector<int>& nums)
 6         {
 7             int sz = nums.size();
 8             vector<pair<int,int>> dp (sz,{1,1});//LISlen times
 9             
10             int LISlen = 1;
11             for(int i = 1;i < sz;i ++)
12             {
13                 for(int j = 0;j < i;j ++)
14                 {
15                     if(nums[i]>nums[j]&&dp[j].first+1>dp[i].first)
16                     {
17                         
18                         dp[i].first = dp[j].first+1;
19                         dp[i].second = dp[j].second;
20                         LISlen = max(LISlen,dp[i].first);
21                     }
22                     else if(nums[i]>nums[j]&&dp[j].first+1==dp[i].first)
23                     {
24                         dp[i].second += dp[j].second;
25                     }
26                 }
27             }
28             
29             int rnt = 0;
30             _for(i,0,sz)
31                 if(dp[i].first==LISlen)
32                     rnt += dp[i].second;
33             return rnt;
34         }
35 };

 

标签:second,nums,int,Number,673,Subsequence,LISlen,dp,first
来源: https://www.cnblogs.com/Asurudo/p/10354420.html