D. Once Again ...
You is given an array of positive integers a1, a2, ..., an x t of length n x T. We know that for any i > n It was true that ai = a i - n. Find the length of the longest non-decreasing sequence of the given array.
Input
The first line contains the space-separated integers: n, T (1≤ n ≤100, 1≤ t ≤10^ 7). The second line contains n space-separated integers a1, a2, ..., C16>an (1≤ ai ≤300).
Output
Print a single number-the length of a sought sequence.
Examplesinput
4 3
3 1 4 2
Output
5
Note
The array given in the sample looks like That:3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2. The elements in Bol D form the largest non-decreasing subsequence.
Test instructions is to give a sequence and K value, this sequence can cycle k times, the longest non-descending subsequence, the value of K is very large, so nlogn also to fry. Think about it, even if all the numbers in the original array are in this sub-sequence, there are only 100, and the rest is sure to be able to insert the numbers at will, then the number is obviously the more the better. Then you can repeat the original array a lot (min (n, k)), and find its longest non-descending subsequence, and the number of occurrences of the most number in the remaining repeating sequence is the answer. (In fact, I played more than 10 minutes to think of, unfortunately found before actually put Nlogn lis write down, I copied the former Orz)
#include <iostream>#include<stdio.h>#include<queue>#include<map>#include<algorithm>using namespacestd;Const intMAXN = 1e4 +Ten;inttt[ the];intNUM[MAXN];intDp[maxn];map<int,int>MP;intMain () {intN, K; while(~SCANF ("%d%d", &n, &k)) {intMaxnum =0, maxcnt =0; for(inti =1; I <= N; i++) {scanf ("%d", &Tt[i]); Mp[tt[i]]++; if(Mp[tt[i]) >maxcnt) {Maxnum=Tt[i]; Maxcnt=Mp[tt[i]]; } } intCNT =0; for(inti =1; I <= min (n, k); i++) { for(intj =1; J <= N; J + +) {num[++CNT] =Tt[j]; } } intval =0; //printf ("%d\n", CNT); for(inti =1; I <= CNT; i++) { intPOS = Upper_bound (DP, DP + val, num[i])-DP; if(pos = = val) dp[val++] =Num[i]; ElseDp[pos] =Num[i]; } if(k > N) val = val + (k-n) *maxcnt; //cout << last << "" << maxcnt << Endl;printf"%d\n", Val); }}
Codeforces Round #323 (Div. 2) d.once Again ...