HDU 5489 Removed Interval 2015 ACM/ICPC Asia Regional Hefei Online (LIS变形)
2024-09-06 08:17:05
定义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 ;
}
最新文章
- 样式重置 css reset
- Canvas实例
- OpenResty 安装 drizzle-nginx-module
- JAVA定时执行任务的三种方法
- Android Priority Job Queue (Job Manager):后台线程任务结果传回前台(三)
- I.MX6 shutdown by software
- bzoj 3744: Gty的妹子序列 主席树+分块
- Android 模仿微信启动动画(转)
- 跨平台utf8转unicode研究实现(2)
- Jasper_chart_create a new stacked chart
- cocos2d-x游戏开发系列教程-超级玛丽09-怪物激活与移动
- 【转】URL和URI的区别
- 《DSP using MATLAB》示例Example6.4
- 属性动画ValueAnimator用法
- 刚在在win8.1下装了ubuntu12.04
- 【Android 应用开发】Android - TabHost 选项卡功能用法详解
- java学习笔记05-运算符
- nginx 多级反向代理获取客户端真实IP
- select标签的相关操作,选中,获取option的值,二级联动
- SimpleDateFormat线程不安全
热门文章
- 利用JS函数制作时钟运行程序
- python 学习笔记8 (模块)
- Json文件转Excel
- 访问WEB-INF下JSP资源的几种方式(转)
- 51nod1255【贪心-栈的应用】
- [51nod] 1091 线段的重叠 贪心
- Animation Blueprint, Set Custom Variables Via C++
- uoj#36. 【清华集训2014】玛里苟斯(线性基+概率期望)
- 数据库性能分析 慢查询 profile工具
- 《深入理解java虚拟机》笔记(5)垃圾回收算法及垃圾收集器