CF #323 DIV2 D题
可以知道,当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题的更多相关文章
- CF #324 DIV2 E题
这题很简单,把目标位置排序,把目标位置在当前位置前面的往前交换,每次都是贪心选择第一个满足这样要求的数字. #include <iostream> #include <cstdio& ...
- CF #324 DIV2 C题
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...
- CF #316 DIV2 D题
D. Tree Requests time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- 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, ...
- CF#345 div2 A\B\C题
A题: 贪心水题,注意1,1这组数据,坑了不少人 #include <iostream> #include <cstring> using namespace std; int ...
- 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 ...
- 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 ...
- Codeforces round 419 div2 补题 CF 816 A-E
A Karen and Morning 水题 注意进位即可 #include<bits/stdc++.h> using namespace std; typedef long long i ...
- codeforces round 418 div2 补题 CF 814 A-E
A An abandoned sentiment from past 水题 #include<bits/stdc++.h> using namespace std; int a[300], ...
随机推荐
- 题解报告:hdu 1232 畅通工程(并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1232 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了 ...
- CSS 样式的优先级(重要,一定要理解)
1. 同一元素引用了多个样式时,排在后面的样式属性的优先级高 例如,下面的 div,同时引用了 [.default] 和 [.user] 中的样式,其中 [.user] 样式中的 width 属性会替 ...
- JQuery 记第N次被坑 - ajax请求字符集问题
前言:两个功能差不多的页面,都是使用$.post()请求后台,页面A传递到后台的中文参数正常,页面B传递到后台的中文参数则为乱码 分析过程: ①使用chrome的开发者工具,分析两个页面的ajax请求 ...
- 记Spring下autowire为name时的一个现象
当autowire为byname时,假如有一个名为“user”的component,恰巧还有另一个属性为“user”,它的set方法为setUser(User user),Spring会强行把comp ...
- SQL基本操作——事务
事务是并发和恢复控制的基本单元. 事务四个属性:原子性.一致性.隔离性.持久性. 原子性:一个事务是一个不可分割的单位,事务中包括的诸多操作要么成功要么都失败. 一致性:事务必须使数据库从一个一致性状 ...
- python中struct.pack()函数和struct.unpack()函数
python中的struct主要是用来处理C结构数据的,读入时先转换为Python的字符串类型,然后再转换为Python的结构化类型,比如元组(tuple)啥的~.一般输入的渠道来源于文件或者网络的二 ...
- [Windows Server 2008] 安装网站伪静态
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:安装IIS伪静 ...
- Python基础——列表、元组操作
列表.元组操作 列表: 列表是Python中最基本的数据结构,列表是最常用的Python数据类型,列表的数据项不需要具有相同的类型.列表中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0 ...
- 【sqli-labs】 less49 GET -Error based -String -Blind -Order By Clause(GET型基于盲注的字符型Order By从句注入)
都是order by的注入,作者连图片都懒得改了... 注意和整型的区别,前引号用提交的引号闭合,后引号用#注释 http://192.168.136.128/sqli-labs-master/Les ...
- inflate(int resource, ViewGroup root, boolean attachToRoot)见解
/** * Inflate a new view hierarchy from the specified xml resource. Throws * {@link InflateException ...