定义f[i]表示以i为开头往后的最长上升子序列,d[i]表示以i为结尾的最长上升子序列。

先nlogn算出f[i],

从i-L开始枚举f[i],表示假设i在最终的LIS中,往[0,i-L)里找到满足ai>aj中dj值最大的。用dj+f[i]更新。

但是这样会少考虑一种情况,即i-L以后都不在最终的LIS里面,这样一定是以[0~i-L)中的某个结尾的,所以还要用d[j]去更新答案。

#include<bits/stdc++.h>
using namespace std; const int maxn = 1e5+;
int a[maxn];
int g[maxn];
int f[maxn]; const int INF = 0x3f3f3f3f; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int T; scanf("%d",&T);
for(int ks = ; ks <= T; ks++){
int N,L,k ; scanf("%d%d",&N,&L);
for(int i = ; i < N; i++) scanf("%d",a+i);
fill(g+,g+N-L+,-INF);
for(int i = N-; i >= L; i--){
k = lower_bound(g+,g+N-i,a[i],greater<int>())-g;
f[i] = k;
g[k] = a[i];
}
memset(g+,0x3f,sizeof(int)*(N-L));
int ans = ;
for(int i = L; i < N; i++){
k = lower_bound(g+,g+i-L+,a[i])-g;
ans = max(k-+f[i],ans);
k = lower_bound(g+,g+i-L+,a[i-L])-g;
ans = max(k,ans);
g[k] = a[i-L];
}
printf("Case #%d: %d\n",ks,ans);
}
return ;
}

最新文章

  1. 样式重置 css reset
  2. Canvas实例
  3. OpenResty 安装 drizzle-nginx-module
  4. JAVA定时执行任务的三种方法
  5. Android Priority Job Queue (Job Manager):后台线程任务结果传回前台(三)
  6. I.MX6 shutdown by software
  7. bzoj 3744: Gty的妹子序列 主席树+分块
  8. Android 模仿微信启动动画(转)
  9. 跨平台utf8转unicode研究实现(2)
  10. Jasper_chart_create a new stacked chart
  11. cocos2d-x游戏开发系列教程-超级玛丽09-怪物激活与移动
  12. 【转】URL和URI的区别
  13. 《DSP using MATLAB》示例Example6.4
  14. 属性动画ValueAnimator用法
  15. 刚在在win8.1下装了ubuntu12.04
  16. 【Android 应用开发】Android - TabHost 选项卡功能用法详解
  17. java学习笔记05-运算符
  18. nginx 多级反向代理获取客户端真实IP
  19. select标签的相关操作,选中,获取option的值,二级联动
  20. SimpleDateFormat线程不安全

热门文章

  1. 利用JS函数制作时钟运行程序
  2. python 学习笔记8 (模块)
  3. Json文件转Excel
  4. 访问WEB-INF下JSP资源的几种方式(转)
  5. 51nod1255【贪心-栈的应用】
  6. [51nod] 1091 线段的重叠 贪心
  7. Animation Blueprint, Set Custom Variables Via C++
  8. uoj#36. 【清华集训2014】玛里苟斯(线性基+概率期望)
  9. 数据库性能分析 慢查询 profile工具
  10. 《深入理解java虚拟机》笔记(5)垃圾回收算法及垃圾收集器