Skip to content

Latest commit

 

History

History
16 lines (14 loc) · 573 Bytes

File metadata and controls

16 lines (14 loc) · 573 Bytes

Idea

This problem is a modified version of Longest Increasing Subsequence.

For this problem, we still need to find out the LIS, which is quite simple:

for j in range(i):
	if nums[i] > nums[j]:
		dp[i] = max(dp[i], dp[j]+1)		

Note that dp[i] represents for the LIS for element i. if dp[i] == dp[j] + 1 and nums[i] > nums[j], this means that element i can be accessed from j:

for j in range(i):
	if dp[i] == dp[j] + 1 and nums[i] > nums[j]:
		count[i] += count[j]