11
22
2015
0

[Codeforces Round #323] Once Again...


D. Once Again...
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an array of positive integers a1, a2, ..., an × T of length n × T. We know that for any i > n it is true that ai = ai - n. Find the length of the longest non-decreasing sequence of the given array.

Input

The first line contains two space-separated integers: nT (1 ≤ n ≤ 1001 ≤ T ≤ 107). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 300).

Output

Print a single number — the length of a sought sequence.

Sample test(s)
input
4 3
3 1 4 2
output
5
Note

The array given in the sample looks like that: 3, 1, 4, 23, 1, 4, 2, 3, 1, 4, 2. The elements in bold form the largest non-decreasing subsequence.

题目大意:给出一个长度为n的序列a,求由T个序列a连接起来形成的新序列的最长不降子序列。


易知求出的序列的形态一定是前后若干个元素加上中间若干个相同的元素。因为每个循环节中至少要取一个元素(取一定比不取优),所以可以分别正着和倒着DP长度为n*n的序列,然后再枚举求解。

代码在此。

Category: 题解 | Tags: DP Codeforces | Read Count: 354

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com