# # 【LeetCode】673. Number of Longest Increasing Subsequence 解题报告（Python）

## # 题目描述：

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.
``````

Note: Length of the given array will be not exceed 2000 and the answer is guaranteed to be fit in 32-bit signed int.

## # 解题方法

``````class Solution(object):
def findNumberOfLIS(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
dp, longest = [[1, 1] for _ in range(len(nums))], 1
for i in range(1, len(nums)):
curr_longest, count = 1, 0
for j in range(i):
if nums[j] < nums[i]:
curr_longest = max(curr_longest, dp[j][0] + 1)
for j in range(i):
if dp[j][0] == curr_longest - 1 and nums[j] < nums[i]:
count += dp[j][1]
dp[i] = [curr_longest, max(count, dp[i][1])]
longest = max(longest, curr_longest)
return sum([item[1] for item in dp if item[0] == longest])
``````

## # 日期

2018 年 4 月 4 日 ———— 清明时节雪纷纷～～下雪了，惊不惊喜，意不意外？