#P2766. 最长不下降子序列问题

    ID: 1771 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp网络流O2优化最大流网络流 24 题

最长不下降子序列问题

Description

Given a sequence of positive integers x1,xnx_1 \ldots, x_n.

  1. Compute the length ss of its longest non-decreasing subsequence.
  2. If each element is allowed to be used at most once, compute the maximum number of non-decreasing subsequences of length ss that can be extracted from the given sequence.
  3. If, in the extracted subsequences, x1x_1 and xnx_n are allowed to be used multiple times (all other elements are still allowed to be used at most once), compute the maximum number of different non-decreasing subsequences of length ss that can be extracted from the given sequence.

Let a1,a2,,asa_1, a_2, \ldots, a_s be the indices used to construct SS, and b1,b2,,bsb_1, b_2, \ldots, b_s be the indices used to construct TT. For all i[1,s1]i \in [1,s-1], we have ai<ai+1a_i \lt a_{i+1} and bi<bi+1b_i \lt b_{i+1}. Then SS and TT are different if and only if there exists i[1,s]i \in [1,s] such that aibia_i \neq b_i.

Input Format

The first line contains a positive integer nn, which is the length of the given sequence. The following lines contain nn positive integers x1,...,xnx_1, ..., x_n.

Output Format

  • The first line is the length ss of the longest non-decreasing subsequence.
  • The second line is the maximum number of non-decreasing subsequences of length ss that can be extracted.
  • The third line is the maximum number of different non-decreasing subsequences of length ss that can be extracted when x1x_1 and xnx_n are allowed to be used multiple times in the extracted subsequences.
4
3 6 2 5
2
2
3

Hint

Constraints: 1n5001 \le n \le 500.

Translated by ChatGPT 5