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 SQL入门用法与原理分析

    Spark SQL是为了让开发人员摆脱自己编写RDD等原生Spark代码而产生的,开发人员只需要写一句SQL语句或者调用API,就能生成(翻译成)对应的SparkJob代码并去执行,开发变得更简洁 注 ...

  2. SDUT1157:小鼠迷宫问题(bfs+dfs)

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1157 题目描述 小鼠a与小鼠b身处一个m×n的 ...

  3. Postman + newman + jenkins 的API自动化测试应用

    一.环境配置 Postman postman 的具体使用可以参考另外一篇文章:postman 做接口测试之学习笔记 Newman 第一步,安装nodejs. 第二步,在nodejs命令行安装newma ...

  4. 一个新人对于DW标签的理解

    标签呢分为 一.一般标签 一般标签内又分为 ① 格式控制标签 格式控制标签的书写格式是: <font .....></font>  以font为开头以/font为结尾 font ...

  5. ftp命令行敲不了

    最先安装了vsftpd,但是命令行敲ftp老是不行 解决方案:ftp命令是ftp客户端,vsftp是ftp服务器,两者不是一个概念.你需要安装ftp客户端 yum install ftp 可以自动安装 ...

  6. 010-centos上安装matlab

    #001-下载matlab_R2015b和破解文件(四个)到百度云盘上下载7.6g#002-上传matlab大文件先安装vm tools,然后直接复制到虚拟机桌面#003-挂载matlab镜像并安装m ...

  7. JSP—作用域

    application: 用于同一个应用内,所有用户之间的数据共享 作用域: request作用域: 在页面转发,包含中同样有效. <% pageContext.include("te ...

  8. ide vscode安装

    在linux系统中安装VSCode(Visual Studio Code)   在linux系统中安装VSCode(Visual Studio Code) 1.从官网下载压缩包(话说下载下来解压就直接 ...

  9. 持续集成之二:搭建SVN服务器(整合Apache+Subversion)

    安装环境 Red Hat Enterprise Linux Server release 7.3 (Maipo) jdk1.7.0_80 rhel-server-7.3-x86_64-dvd.iso ...

  10. linux常用命令:用SecureCRT来上传和下载文件

    用SSH管理linux服务器时经常需要远程与本地之间交互文件.而直接用SecureCRT自带的上传下载功能无疑是最方便的,SecureCRT下的文件传输协议有ASCII.Xmodem.Zmodem. ...