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 ≤ 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.

Examples
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 bold form the largest non-decreasing subsequence.

题目链接:http://codeforces.com/contest/583/problem/D

题意:给你一个序列n,有T个连续这样的序列,求最长不下降子序列的长度;

思路:发现T很大,n很小对吧,

   显然中间肯定是有一段是连续的相同的数对吧;

   开始想前面取一个LIS,最后取一个LIS,中间相同,数量最多的那个数;

     这个做法错误,可能后面的前一个还能多取;

   如果T<=n比较小,我们只需要暴力跑LIS即可;

   现在讨论T>n的情况;

   然后发现只有n个数,也就是说最后的LIS最多只有n段不同的数;

   也就是说我们只需要拿出n段序列出来,跑LIS即可;

   因为最多n段,然后取完n段,多余的可以从中间插入;

   

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define mk make_pair
#define eps 1e-7
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e5+,M=1e6+,inf=;
const ll INF=1e18+,mod=; /// 数组大小
int arr[N],ans[N],len;
int binary_search(int i)
{
int left,right,mid;
left=,right=len;
while(left<right)
{
mid = left+(right-left)/;
if(ans[mid]>arr[i]) right=mid;
else left=mid+;
}
return left;
}
int LIS(int p)
{
ans[] = arr[];
len=;
for(int i=; i<=p; ++i)
{
if(arr[i]>=ans[len])
ans[++len]=arr[i];
else
{
int pos=binary_search(i);
ans[pos] = arr[i];
}
}
return len;
}
int flag[N];
int main()
{
int n,T,maxx=;
scanf("%d%d",&n,&T);
for(int i=;i<=n;i++)
scanf("%d",&arr[i]),flag[arr[i]]++,maxx=max(maxx,flag[arr[i]]);
for(int i=;i<n;i++)
for(int j=;j<=n;j++)
arr[i*n+j]=arr[j];
if(n>=T)printf("%d\n",LIS(n*T));
else printf("%d\n",LIS(n*n)+maxx*(T-n));
return ;
}

Codeforces Round #323 (Div. 2) D. Once Again... 乱搞+LIS的更多相关文章

  1. Codeforces Round #324 (Div. 2) Marina and Vasya 乱搞推理

    原题链接:http://codeforces.com/contest/584/problem/C 题意: 定义$f(s1,s2)$为$s1,s2$不同的字母的个数.现在让你构造一个串$s3$,使得$f ...

  2. Codeforces Round #323 (Div. 1) B. Once Again... 暴力

    B. Once Again... Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/582/probl ...

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

    C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C ...

  4. 重复T次的LIS的dp Codeforces Round #323 (Div. 2) D

    http://codeforces.com/contest/583/problem/D 原题:You are given an array of positive integers a1, a2, . ...

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

    题目链接:http://codeforces.com/contest/583/problem/C C. GCD Table time limit per test 2 seconds memory l ...

  6. 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 define ...

  7. Codeforces Round #323 (Div. 1) A. GCD Table

    A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

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

    E - Superior Periodic Subarrays 好难的一题啊... 这个博客讲的很好,搬运一下. https://blog.csdn.net/thy_asdf/article/deta ...

  9. Codeforces Round #323 (Div. 2) D 582B Once Again...(快速幂)

    A[i][j]表示在循环节下标i开头j结尾的最长不减子序列,这个序列的长度为p,另外一个长度为q的序列对应的矩阵为B[i][j], 将两序列合并,新的序列对应矩阵C[i][j] = max(A[i][ ...

随机推荐

  1. Spark Streaming性能优化: 如何在生产环境下应对流数据峰值巨变

    1.为什么引入Backpressure 默认情况下,Spark Streaming通过Receiver以生产者生产数据的速率接收数据,计算过程中会出现batch processing time > ...

  2. 【转】SVM入门(一)SVM的八股简介

    (一)SVM的八股简介 支持向量机(Support Vector Machine)是Cortes和Vapnik于1995年首先提出的,它在解决小样本.非线性及高维模式识别中表现出许多特有的优势,并能够 ...

  3. [LeetCode] 1. Two Sum_Easy tag: Hash Table

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  4. centos 专题-各种配置应有尽有

    你想要的在这里都能得到解决: http://www.linuxidc.com/topicnews.aspx?tid=14

  5. Summary: Lowest Common Ancestor in a Binary Tree & Shortest Path In a Binary Tree

    转自:Pavel's Blog Now let's say we want to find the LCA for nodes 4 and 9, we will need to traverse th ...

  6. LinkedList详解

    一.LinkedList的介绍与特点. 1.继承实现关系. 实现了双端队列接口Deque,因此具有双端队列的功能:addFirt,addLast,offerFirt,offerLast,removeF ...

  7. 用python实现一个简单的socket网络聊天通讯 (Linux --py2.7平台与windows--py3.6平台)

    windows   --> windows 写法均在py3.6 客户端写法 import socket client = socket.socket() client.connect(('192 ...

  8. Jtester+unitils+testng:DAO单元测试文件模板自动生成

    定位 本文适合于不愿意手工编写而想自动化生成DAO单元测试的筒鞋.成果是不能照搬的,但其中的"创建模板.填充内容.自动生成"思想是可以复用的.读完本文,可以了解 Python 读取 ...

  9. 【转】编程思想之多线程与多进程(3)——Java中的多线程

    <编程思想之多线程与多进程(1)——以操作系统的角度述说线程与进程>一文详细讲述了线程.进程的关系及在操作系统中的表现,这是多线程学习必须了解的基础.本文将接着讲一下Java中多线程程序的 ...

  10. python excel操作单元格复制和读取的两种方法

    操作单元格 新建一个sheet, 单元格赋值(两种方法) 单元格A1赋值为’xiaxiaoxu’ 单元格A2赋值为‘xufengchai’ 打印A1和A2单元格的值(两种方法) #coding=utf ...