Codeforces Round #323 (Div. 2) D. Once Again ... Violence + Longest non-descending subsequence

Source: Internet
Author: User

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.

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, 2, 3, 1, 4, 2, 3, 1, 4, 2. The elements in Bol D form the largest non-decreasing subsequence.

Test instructions: The longest non-descending subsequence length for you to ask for n*t

The puzzle: Because it is the T-N arrangement, the middle segment must be the same, it must be the largest number of n permutations, in t less than 100 is the violent DP, 100 when the calculation of the rain is good

///1085422276#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<queue>#include<cmath>#include<map>#include<bitset>#include<Set>#include<vector>using namespacestd; typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))#defineMeminf (a) memset (A,127,sizeof (a));#defineTS printf ("111111\n");#definefor (I,A,B) for (int i=a;i<=b;i++)#defineForj (I,A,B) for (int i=a;i>=b;i--)#defineREAD (a,b,c) scanf ("%d%d%d", &a,&b,&c)#defineMoD 1000000007#defineINF 100000inline ll read () {ll x=0, f=1; CharCh=GetChar ();  while(ch<'0'|| Ch>'9')    {        if(ch=='-') f=-1; CH=GetChar (); }     while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; CH=GetChar (); }    returnx*F;}//****************************************#defineMAXN 100+5intA[MAXN];intdp[30005];inthashs[ -];intMain () {intn=read (); intt=read (); For (I,1, N) {scanf ("%d",&A[i]); } for (I,0N102) dp[i]=1; if(t<= -) {for (I,1, T) {for (J,1, N) {                 for(intk=1; k<j+n* (I-1); k++)                {                    inttmp=k%N; if(tmp==0) tmp=N; if(a[j]>=a[tmp]) dp[j+n* (I-1)]=max (dp[j+n* (i-1)],dp[k]+1); }            }        }        intmm=-1;  for(intI=1; i<=n*t;i++) mm=Max (DP[I],MM); cout<<mm<<Endl; }    Else{for (I,1, -) {for (J,1, N) {                 for(intk=1; k<j+n* (I-1); k++)                {                    inttmp=k%N; if(tmp==0) tmp=N; if(a[j]>=a[tmp]) dp[j+n* (I-1)]=max (dp[j+n* (i-1)],dp[k]+1); }            }        }        intmm=-1, flag,ans=0;  for(intI=1; i<=n* -; i++) mm=Max (DP[I],MM);  for(intI=1; i<=n;i++) {Hashs[a[i]]++; if(Hashs[a[i]]>ans) ans=Hashs[a[i]]; } cout<<mm+ (t -) *ans<<Endl; }    return 0;}
Code

Codeforces Round #323 (Div. 2) D. Once Again ... Violence + Longest non-descending subsequence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.