Problem 451
Number of Longest Increasing Subsequences
Medium · 20 pts · Array, Dynamic Programming
Problem
Count how many longest strictly increasing subsequences the array has. A subsequence keeps some elements in their original order; two subsequences are different if they use a different set of positions, even if their values are the same. For each position, track both the length of the longest increasing subsequence ending there and how many such subsequences there are. Print the count modulo 1000000007. Keep the counts in a 64-bit integer type (long long in C++, long in Java) and take the remainder after every addition and multiplication: adding or multiplying two remainders can be larger than a 32-bit int can hold (Python needs nothing special).
Input
First line: N. Second line: N integers.
Output
Print the number of longest increasing subsequences modulo 1000000007.
Constraints
1 <= N <= 2000; -1000000 <= A[i] <= 1000000
Example input
5 1 3 5 4 7
Example output
2
Explanation
In 1 3 5 4 7 the longest increasing subsequences have length 4, and there are two of them: 1 3 4 7 and 1 3 5 7.