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], ...
随机推荐
- java基础之吃货联盟
因为用的是普通数组,所以编写的代码可能比较长,而且有的功能还比较不健全,代码如下: 0.定义数组(因为用static修饰可以不用New,比较方便,但可能比较损耗性能) //订餐人名字 static S ...
- Java常用类库(二):Iterator迭代器和子范围视图
今天介绍集合类的以下内容: l Iterator迭代器 l 子范围视图简介 Iterator迭代器: 应该将java迭代器认为是位于两个元素之间, 当调用next 时,迭代器就越过下一个元素,并返 ...
- java学习笔记_BeatBox(GUI部分)
import java.awt.*; import javax.swing.*; public class BeatBox { JFrame theFrame; JPanel mainPanel; S ...
- 线性回归的Cost function实现
此处使用Octave来实现 线性方程的代价函数: 代价函数: X 是测试值,假设用矩阵表示为 为了方便用矩阵计算我们把X加一列 1 : 同时 那么h( ...
- JS——缓慢动画封装案例
手风琴 1.排他思想 2.ul宽度需要大一点,防止li撑开跑下去 3.一个变大其他所有变小,变小不能太小,不然会出现空白 <!DOCTYPE html> <html lang=&qu ...
- [源码阅读]RocketMQ-策略篇
一:为什么要阅读rocketmq的源码? 1 可以了解mq的底层实现逻辑. 二:打算怎么读,行动路径是哪儿些? 1: 本地启动 2 分步调试 3 fork项目,添加中文注释,提交到自己的代码库.并改 ...
- HDU_5723_最小生成树+任意两点距离的期望
Abandoned country Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- Makefile精髓篇【转】
什么是makefile?或许非常多Winodws的程序猿都不知道这个东西,由于那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和professional的程序猿,makefile还是 ...
- Ubuntu 18.04 如何固定图标到任务栏
参考 https://blog.csdn.net/u014160286/article/details/81631863
- 洛谷——P1966 火柴排队&&P1774 最接近神的人_NOI导刊2010提高(02)
P1966 火柴排队 这题贪心显然,即将两序列中第k大的数的位置保持一致,证明略: 树状数组求逆序对啦 浅谈树状数组求逆序对及离散化的几种方式及应用 方法:从前向后每次将数插入到bit(树状数组)中, ...