problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::number_of_longest_increasing_subsequence::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static int findNumberOfLIS (vector< int > &nums)
 

详细描述

在文件 leetcode.h2499 行定义.

成员函数说明

◆ findNumberOfLIS()

int leetcode::number_of_longest_increasing_subsequence::Solution::findNumberOfLIS ( vector< int > &  nums)
static

在文件 leetcode.cpp6733 行定义.

6733 {
6734 const int n = nums.size();
6735 vector dp(n, map<unsigned, unsigned>());//dp[i][j] = number of increasing subsequence end with i, length is j
6736 for(int i = 0; i < n; i++) {
6737 dp[i][1] = 1;
6738 }
6739 unsigned max_len = 1;
6740 for(int i = 0; i < n; i++) {
6741 for(int j = i + 1; j < n; j++) {
6742 auto &[len, cnt] = *dp[i].rbegin();
6743 if(nums[j] > nums[i]) {
6744 dp[j][len + 1] += cnt;
6745 max_len = max(max_len, len + 1);
6746 }
6747 }
6748 }
6749 unsigned ans = 0;
6750 for(int i = 0; i < n; i++) {
6751 ans += dp[i][max_len];
6752 }
6753 return ans;
6754 }

被这些函数引用 leetcode::number_of_longest_increasing_subsequence::TEST().


该类的文档由以下文件生成: