LeetCode 673. Number of Longest Increasing Subsequence 最长递增子序列的个数 (C++/Java)
题目: Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: Input: [1,3,5,4,7] Output: 2 Explanation: The two longest increasing subsequence are [1, 3, 4, 7] and [1, 3, 5, 7]. Example 2: Input: [2,2,2,2,2] Output: 5 Explanation: The length of longest continuous increasing subsequence is 1, and there are 5 subsequences' length is 1, so output 5. 分析: 求出最长递增子序列的个数,我们使用lens[i]表示以nums[i]为结尾的递增子序列中元素的个数也就是长度,以time[i]表示以nums[i]为结尾的递增子序列出现的次数,遍历nums数组,维护这两个数组。 遍历nums[i]这个元素,都要和i前面的元素进行比较(用j进行遍历),如果nums[i]大于nums[j],意味着nums[i]可以拼接到nums[j]后面,产生一个更长的子序列,如果lens[i]