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], ...
随机推荐
- [Swift通天遁地]七、数据与安全-(16)检测Apple设备是否越狱
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 微信小程序商品展示页面(仿咸鱼)
项目中做了一个商品发布展示的页面,记录下来 解决问题: 想在setData中更改数组具体下标中的某个值: let one = "lowMoney[" + 0 + "].m ...
- ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/pod
因为突然要用到cocospod,突然发现在使用pod install的时候出现 -bash: pod: command not found 我去-不知道为什么,然后我就想重新安装下cocospod,在 ...
- 安卓5.0新特性之Palette
根据图片来决定标题的颜色和标题栏的背景色,这样视觉上更具有冲击力和新鲜感,而不像统一色调那样呆板. Palette这个类能提取以下突出的颜色: Vibrant(充满活力的) Vibrant dark( ...
- 【转】Linux账号管理之useradd
转自:http://www.jb51.net/article/45848.htm Linux 系统是一个多用户多任务的分时操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然 ...
- No operations allowed after connection closed--转
https://www.jianshu.com/p/1626d41572f2 Spring boot的单数据源配置比较简单,只需要在application.properties配置相关的jdbc连接的 ...
- echarts通过ajax请求展示多叉树
背景:在sqlserver使用过程中经常由于各种原因会出现阻塞,并发数较高,很难肉眼看出那个session阻塞了其他process,通过sql查询出根源也需要大量的重复操作才能够找到. 因此就有这方面 ...
- html——行内元素、块元素、行内块元素
行内元素:span ,a, ,strong , em, del, ins.特点:在一行上显示:不能直接设置宽高:元素的宽和高就是内容撑开的宽高. 块元素:div,h1-h6,p,ul,li.特 ...
- 4星|《超级技术:改变未来社会和商业的技术趋势》:AI对人友好吗
超级技术:改变未来社会和商业的技术趋势 多位专家或经济学人编辑关于未来的预测,梅琳达·盖茨写了其中一章.在同类书中属于水平比较高的,专家只写自己熟悉的领域,分析与预测有理有据而不仅仅是畅想性质. 以下 ...
- DateTimePicker 控件置空
dtOrderDateFrom.Format = DateTimePickerFormat.Custom; dtOrderDateFrom.CustomFormat = " "; ...