Codeforces Round #323 (Div. 2) D. Once Again... 暴力+最长非递减子序列

                                                                              D. Once Again...

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 ≤ 100, 1 ≤ 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 33 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 bold form the largest non-decreasing subsequence.

题意:要你求n*T的最长非递减子序列长度

题解:由于是T个n排列,中间段必定是相同的,也必定是n排列中数最多的,在T小于100是暴力dp,大雨100时计算就好了

///1085422276
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<bitset>
#include<set>
#include<vector>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a));
#define TS printf("111111\n");
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define FORJ(i,a,b) for(int i=a;i>=b;i--)
#define READ(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define mod 1000000007
#define inf 100000
inline ll read()
{
    ll x=0,f=1;
    char ch=getchar();
    while(ch<‘0‘||ch>‘9‘)
    {
        if(ch==‘-‘)f=-1;
        ch=getchar();
    }
    while(ch>=‘0‘&&ch<=‘9‘)
    {
        x=x*10+ch-‘0‘;
        ch=getchar();
    }
    return x*f;
}
//****************************************

#define maxn 100+5
int a[maxn];
int dp[30005];
int hashs[400];
int main()
{

    int n=read();
    int T=read();
    FOR(i,1,n)
    {
        scanf("%d",&a[i]);
    }
    FOR(i,0,n*102)dp[i]=1;
    if(T<=100)
    {
        FOR(i,1,T)
        {
            FOR(j,1,n)
            {
                for(int k=1;k<j+n*(i-1);k++)
                {
                    int tmp=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);
                }
            }
        }
        int mm=-1;
        for(int i=1;i<=n*T;i++)mm=max(dp[i],mm);
        cout<<mm<<endl;
    }
    else {

       FOR(i,1,100)
        {
            FOR(j,1,n)
            {
                for(int k=1;k<j+n*(i-1);k++)
                {
                    int tmp=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);
                }
            }
        }
        int mm=-1,flag,ans=0;
        for(int i=1;i<=n*100;i++)mm=max(dp[i],mm);
           for(int i=1;i<=n;i++)
           {
               hashs[a[i]]++;
               if(hashs[a[i]]>ans)ans=hashs[a[i]];
           }
           cout<<mm+(T-100)*ans<<endl;
    }
    return 0;
}

代码

时间: 2024-10-11 01:29:30

Codeforces Round #323 (Div. 2) D. Once Again... 暴力+最长非递减子序列的相关文章

Codeforces Round #359 (Div. 2) C. Robbers&#39; watch (暴力DFS)

题目链接:http://codeforces.com/problemset/problem/686/C 给你n和m,问你有多少对(a, b) 满足0<=a <n 且 0 <=b < m 且a的7进制和n-1的7进制位数相同 且b的7进制和m-1的7进制位数相同,还有a和b的7进制上的每位上的数各不相同. 看懂题目,就很简单了,先判断a和b的7进制位数是否超过7,不超过的话就dfs暴力枚举计算就可以了. 1 //#pragma comment(linker, "/STACK

Codeforces Round #323 (Div. 2)

被进爷坑了,第二天的比赛改到了12点 水 A - Asphalting Roads /************************************************ * Author :Running_Time * Created Time :2015/10/3 星期六 21:53:09 * File Name :A.cpp ************************************************/ #include <cstdio> #include

2017-5-2-Train:Codeforces Round #323 (Div. 2)

A. Asphalting Roads(模拟) City X consists of n vertical and n horizontal infinite roads, forming n × n intersections. Roads (both vertical and horizontal) are numbered from 1 to n, and the intersections are indicated by the numbers of the roads that fo

Codeforces Round #323 (Div. 2) D.Once Again...

D. Once Again... 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

Codeforces Round #323 (Div. 2) C. GCD Table

C. GCD Table The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both

Codeforces Round #323 (Div. 2) E - Superior Periodic Subarrays

E - Superior Periodic Subarrays 好难的一题啊... 这个博客讲的很好,搬运一下. https://blog.csdn.net/thy_asdf/article/details/49406133 #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define pii pair<int,int> #de

Codeforces Round #349 (Div. 2) D. World Tour 暴力最短路

D. World Tour A famous sculptor Cicasso goes to a world tour! Well, it is not actually a world-wide. But not everyone should have the opportunity to see works of sculptor, shouldn't he? Otherwise there will be no any exclusivity. So Cicasso will enti

Codeforces Round #272 (Div. 2) Dreamoon and WiFi 暴力

B. Dreamoon and WiFi Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the following two types: Go 1 unit towards the

Codeforces Round #544 (Div. 3) C. Balanced Team [暴力剪枝]

You are a coach at your local university. There are n n students under your supervision, the programming skill of the i i -th student is a i ai . You have to create a team for a new programming competition. As you know, the more students some team ha