#FT0000101. Số dãy con tăng dài nhất (Number of Longest Increasing Subsequence)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Số dãy con tăng dài nhất (Number of Longest Increasing Subsequence)
Number of Longest Increasing Subsequence
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an integer array . A subsequence is formed by selecting positions in increasing order, without requiring those positions to be consecutive. A subsequence is strictly increasing if each selected value is smaller than the following selected value.
Let be the maximum length of a strictly increasing subsequence. Count the number of ways to select a subsequence of length exactly .
Subsequences with different index sets are counted separately even if their selected values are identical. The answer is guaranteed to fit in a signed 32-bit integer.
Input
- The first line contains integer , the array length.
- The second line contains exactly integers in order.
Output
Print one integer: the number of strictly increasing subsequences of maximum length.
Subtasks
- Subtask 1 (20 points): ; for every ; the answer fits in a signed 32-bit integer.
- Subtask 2 (30 points): ; for every ; the answer fits in a signed 32-bit integer.
- Subtask 3 (50 points): ; for every ; the answer fits in a signed 32-bit integer.
Examples
Example 1
Input
5
1 3 5 4 7
Output
2
Explanation
For , the maximum increasing length is . Exactly two index sets achieve it: produces , while produces . Values cannot both be consecutive in an increasing subsequence because . The output is 2.
Example 2
Input
5
2 2 2 2 2
Output
5
Explanation
All five values are , so no strictly increasing subsequence has length greater than . Each of the five positions forms a different length- subsequence. The output is 5.