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

Posted Asurudo Jyo の 倉 庫

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 };

 

以上是关于Leetcode-673 (Number of Longest Increasing Subsequence)最长递增子序列的个数的主要内容,如果未能解决你的问题,请参考以下文章

CF1175F The Number of Subpermutations

[AtCoder arc090F]Number of Digits

cf1151e number of components

LeetCode 673. 最长递增子序列的个数

Leetcode 673.最长递增子序列的个数

[LeetCode] Prime Number of Set Bits in Binary Representation