标签:length incr span turn div else col code ++
class Solution { public: int findNumberOfLIS(vector<int>& nums) { if (nums.size() == 0) return 0; pair<int,int> res = {0, 0}; // <length,count> vector<pair<int,int>> dp(nums.size(), {1,1}); // pair: length, count for (int i = 0; i < nums.size(); i++) { for (int j = 0; j < i; j++) { if (nums[j] < nums[i]) { if (dp[j].first + 1 == dp[i].first) { dp[i].second += dp[j].second; } else if (dp[j].first + 1 > dp[i].first) { dp[i].first = dp[j].first + 1; dp[i].second = dp[j].second; } } } } for (int i = 0; i < nums.size(); i++) { if (dp[i].first == res.first) res.second += dp[i].second; else if (dp[i].first > res.first) { res = dp[i]; } } return res.second; } };
673. Number of Longest Increasing Subsequence
标签:length incr span turn div else col code ++
原文地址:https://www.cnblogs.com/JTechRoad/p/9122071.html