可以知道,当T较大时,对于LIS,肯定会有很长的一部分是重复的,而这重复的部分,只能是一个block中出现次数最多的数字组成一序列。所以,对于T》1000时,可以直接求出LIS,剩下T-=1000直接求出现次数最多的数字的个数即可。其实可以不用到1000,只需到n即可。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector> using namespace std; const int MAX=105;
int p[MAX*MAX*10];
int a[MAX],n,t,m;
int dp[MAX*MAX*10]; int bin(int l,int r,int key){
while(l<=r){
int mid=(l+r)>>1;
if(dp[mid]>key&&dp[mid-1]<=key) return mid;
if(dp[mid]>key) r=mid-1;
else l=mid+1;
}
return 1;
} int LIS(int len){
int res=1; dp[res]=p[1];
for(int i=2;i<=len;i++){
if(p[i]>=dp[res]){
dp[++res]=p[i];
}
else{
int pos=bin(1,res,p[i]);
dp[pos]=p[i];
}
}
///cout<<res<<endl;
return res;
} void slove(int l){
int ans=LIS(l);
/// cout<<ans<<endl;
sort(a+1,a+1+n);
int counts=1,maxlen=1;
for(int i=2;i<=n;i++){
if(a[i]==a[i-1]) counts++;
else{
if(counts>maxlen) maxlen=counts;
counts=1;
}
}
if(counts>maxlen) maxlen=counts;
printf("%d\n",ans+(t-m)*maxlen);
} int main(){
while(scanf("%d%d",&n,&t)!=EOF){
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
m=min(1000,t);
dp[0]=-1e9+7;
for(int i=0;i<m;i++){
for(int j=1;j<=n;j++){
p[i*n+j]=a[j];
dp[i*n+j]=1e9+7;
}
}
slove(m*n);
}
return 0;
}

  

CF #323 DIV2 D题的更多相关文章

  1. CF #324 DIV2 E题

    这题很简单,把目标位置排序,把目标位置在当前位置前面的往前交换,每次都是贪心选择第一个满足这样要求的数字. #include <iostream> #include <cstdio& ...

  2. CF #324 DIV2 C题

    #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...

  3. CF #316 DIV2 D题

    D. Tree Requests time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  4. cf 442 div2 F. Ann and Books(莫队算法)

    cf 442 div2 F. Ann and Books(莫队算法) 题意: \(给出n和k,和a_i,sum_i表示前i个数的和,有q个查询[l,r]\) 每次查询区间\([l,r]内有多少对(i, ...

  5. CF#345 div2 A\B\C题

    A题: 贪心水题,注意1,1这组数据,坑了不少人 #include <iostream> #include <cstring> using namespace std; int ...

  6. codeforces round 422 div2 补题 CF 822 A-F

    A I'm bored with life 水题 #include<bits/stdc++.h> using namespace std; typedef long long int LL ...

  7. codeforces round 421 div2 补题 CF 820 A-E

    A Mister B and Book Reading  O(n)暴力即可 #include<bits/stdc++.h> using namespace std; typedef lon ...

  8. Codeforces round 419 div2 补题 CF 816 A-E

    A Karen and Morning 水题 注意进位即可 #include<bits/stdc++.h> using namespace std; typedef long long i ...

  9. codeforces round 418 div2 补题 CF 814 A-E

    A An abandoned sentiment from past 水题 #include<bits/stdc++.h> using namespace std; int a[300], ...

随机推荐

  1. python之set集合及深浅拷贝

    一.知识点补充 1.1字符串的基本操作 li =["李李嘉诚", "麻花藤", "⻩黄海海峰", "刘嘉玲"] s = ...

  2. 跨服务器进行SQL Server数据库的数据处理

    exec sp_addlinkedserver 'ITDB', ' ', 'SQLOLEDB', '服务器IP' exec sp_addlinkedsrvlogin 'ITDB', 'false ', ...

  3. asp.net——统计输入的字符数目

    asp.net——统计输入的字符数目 题目: 在页面中有一个TextBox输入框,一个显示文字用的Label,一个提交按钮Button.在TextBox中输入一段英文字母,点击按钮提交后统计其中字母‘ ...

  4. 努比亚(nubia) Z18 mini NX611J 解锁BootLoader 并刷入recovery ROOT

    努比亚(nubia)  Z18 mini NX611J解锁BootLoader 并刷入recovery ROOT 工具下载链接:https://pan.baidu.com/s/1toU-mTR9FNE ...

  5. Leetcode0143--Reorder List 链表重排

    [转载请注明]https://www.cnblogs.com/igoslly/p/9351564.html 具体的图示可查看 链接 代码一 /** * Definition for singly-li ...

  6. Android studio 中R.menu的创建

    对于Android开发中的menu没有声明的情况: 首先,将鼠标定位到红色的menu上面, 然后,Alt+enter组合键,建立文件menu, 然后将以下代码复制进去: <item androi ...

  7. 使用Jupter Notebook实现简单的神经网络

    参考:http://python.jobbole.com/82208/ 注:1)# %matplotlib inline 注解可以使Jupyter中显示图片 2)注意包的导入方式 一.使用的Pytho ...

  8. VMWare 安装Ubuntu 16.04

    1.新建虚拟机 (1)点击文件-->新建虚拟机 (2)选择 自定义(高级)--> 下一步 (3)选择Workstation 12.0 --> 下一步 (4)选择 稍后安装操作系统 - ...

  9. jQuery——事件操作

    事件绑定 1.简单事件绑定 $("button").click(function () {})//可重复绑定,不会被层叠 2.bind():不推荐使用 $("button ...

  10. Linux下的文件结构,及对应文件夹的作用

    Linux下的文件结构,及对应文件夹的作用 /bin 二进制可执行命令 /dev 设备特殊文件 /etc 系统管理和配置文件 /etc/rc.d 启动的配置文件和脚本 /home 用户主目录的基点,比 ...