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

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. const int MAX=105;
  10. int p[MAX*MAX*10];
  11. int a[MAX],n,t,m;
  12. int dp[MAX*MAX*10];
  13.  
  14. int bin(int l,int r,int key){
  15. while(l<=r){
  16. int mid=(l+r)>>1;
  17. if(dp[mid]>key&&dp[mid-1]<=key) return mid;
  18. if(dp[mid]>key) r=mid-1;
  19. else l=mid+1;
  20. }
  21. return 1;
  22. }
  23.  
  24. int LIS(int len){
  25. int res=1; dp[res]=p[1];
  26. for(int i=2;i<=len;i++){
  27. if(p[i]>=dp[res]){
  28. dp[++res]=p[i];
  29. }
  30. else{
  31. int pos=bin(1,res,p[i]);
  32. dp[pos]=p[i];
  33. }
  34. }
  35. ///cout<<res<<endl;
  36. return res;
  37. }
  38.  
  39. void slove(int l){
  40. int ans=LIS(l);
  41. /// cout<<ans<<endl;
  42. sort(a+1,a+1+n);
  43. int counts=1,maxlen=1;
  44. for(int i=2;i<=n;i++){
  45. if(a[i]==a[i-1]) counts++;
  46. else{
  47. if(counts>maxlen) maxlen=counts;
  48. counts=1;
  49. }
  50. }
  51. if(counts>maxlen) maxlen=counts;
  52. printf("%d\n",ans+(t-m)*maxlen);
  53. }
  54.  
  55. int main(){
  56. while(scanf("%d%d",&n,&t)!=EOF){
  57. for(int i=1;i<=n;i++){
  58. scanf("%d",&a[i]);
  59. }
  60. m=min(1000,t);
  61. dp[0]=-1e9+7;
  62. for(int i=0;i<m;i++){
  63. for(int j=1;j<=n;j++){
  64. p[i*n+j]=a[j];
  65. dp[i*n+j]=1e9+7;
  66. }
  67. }
  68. slove(m*n);
  69. }
  70. return 0;
  71. }

  

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. [Swift通天遁地]七、数据与安全-(16)检测Apple设备是否越狱

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  2. 微信小程序商品展示页面(仿咸鱼)

    项目中做了一个商品发布展示的页面,记录下来 解决问题: 想在setData中更改数组具体下标中的某个值: let one = "lowMoney[" + 0 + "].m ...

  3. ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/pod

    因为突然要用到cocospod,突然发现在使用pod install的时候出现 -bash: pod: command not found 我去-不知道为什么,然后我就想重新安装下cocospod,在 ...

  4. 安卓5.0新特性之Palette

    根据图片来决定标题的颜色和标题栏的背景色,这样视觉上更具有冲击力和新鲜感,而不像统一色调那样呆板. Palette这个类能提取以下突出的颜色: Vibrant(充满活力的) Vibrant dark( ...

  5. 【转】Linux账号管理之useradd

    转自:http://www.jb51.net/article/45848.htm Linux 系统是一个多用户多任务的分时操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然 ...

  6. No operations allowed after connection closed--转

    https://www.jianshu.com/p/1626d41572f2 Spring boot的单数据源配置比较简单,只需要在application.properties配置相关的jdbc连接的 ...

  7. echarts通过ajax请求展示多叉树

    背景:在sqlserver使用过程中经常由于各种原因会出现阻塞,并发数较高,很难肉眼看出那个session阻塞了其他process,通过sql查询出根源也需要大量的重复操作才能够找到. 因此就有这方面 ...

  8. html——行内元素、块元素、行内块元素

    行内元素:span  ,a,  ,strong , em,  del,  ins.特点:在一行上显示:不能直接设置宽高:元素的宽和高就是内容撑开的宽高. 块元素:div,h1-h6,p,ul,li.特 ...

  9. 4星|《超级技术:改变未来社会和商业的技术趋势》:AI对人友好吗

    超级技术:改变未来社会和商业的技术趋势 多位专家或经济学人编辑关于未来的预测,梅琳达·盖茨写了其中一章.在同类书中属于水平比较高的,专家只写自己熟悉的领域,分析与预测有理有据而不仅仅是畅想性质. 以下 ...

  10. DateTimePicker 控件置空

    dtOrderDateFrom.Format = DateTimePickerFormat.Custom; dtOrderDateFrom.CustomFormat = " "; ...