简单dp hdu 5532 Almost Sorted Array nlogn 的最长非严格单调子序列
来源:互联网 发布:ubuntu dokuwiki 编辑:程序博客网 时间:2024/05/19 11:47
We say an array is sorted if its elements are in non-decreasing order or non-increasing order. We say an array is almost sorted if we can remove exactly one element from it, and the remaining array is sorted. Now you are given an array
There are at most 20 test cases with
332 1 733 2 153 1 4 1 5
YESYESNO
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
const int inf=1e9+7;
const int maxn=1e5+10;
using namespace std;
int a[maxn],b[maxn],c[maxn];
int n;
int binary_search(int x){ //二分搜索
int l=1,r=n;
while(l<r){
int mid=(l+r)>>1;
if(b[mid]>x) r=mid;
else l=mid+1;
}
return l;
}
bool LIS(const int *a){ //LIS
memset(b,inf,sizeof(b));
b[0]=0;
int len=0;
for(int i=1; i<=n; ++i){
int k=binary_search(a[i]);//i位置的LIS为idx
len=max(k,len);
b[k]=a[i];
}
if(len>=n-1) return true; //满足条件即可
return false;
}
int main(){
int t;scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=1; i<=n; ++i){
scanf("%d",&a[i]);
c[n-i+1]=a[i];
}
if(LIS(a)||LIS(c)) puts("YES");
else puts("NO");
}
return 0;
}
- 简单dp hdu 5532 Almost Sorted Array nlogn 的最长非严格单调子序列
- HDU 5532 Almost Sorted Array(最长不下降子序列nlogn模板)
- Almost Sorted Array(HDU 5532 单调递增子序列)
- hdu 5532 Almost Sorted Array 最长上升子序列
- hdu-5532 Almost Sorted Array(最长单调不xx序列)
- hdu 5532 Almost Sorted Array(最长不上升子序列、暴力)
- HDU 5532 Almost Sorted Array(思维,最长递增子序列,模拟)
- hdu 5532 Almost Sorted Array(最长上升(不下降)子序列和最长下降(不上升)子序列)
- HDU 5532 Almost Sorted Array(最长非递减子序列 模板题)——2015ACM/ICPC亚洲区长春站
- [hdu 5532] [2015ACM/ICPC亚洲区长春站 ] Almost Sorted Array 最长不下降子序列
- hdu 5532【最长非递增子序列 时间复杂度 nlogn】
- hdu5532 Almost Sorted Array--最长上升子序列
- HDU5532 Almost Sorted Array(最长不上升子序列)
- HDU5532 Almost Sorted Array(最长子序列)
- HDU 5532 Almost Sorted Array (dp)
- hdu-6197 array array array(最长上升子序列(LIS)长度的O(nlogn)算法)
- 最长严格上升子序列O(nlogn)
- 单调递增最长子序列 O(nlogn)
- CDH5离线安装(最新版5.3.3内置hadoop2.5.0)
- 会话管理技能树
- SpringMvc学习笔记(三)对Servlet API和json的支持
- fork,你拿什么证明你的写时拷贝(COW)
- gdb 打印vector
- 简单dp hdu 5532 Almost Sorted Array nlogn 的最长非严格单调子序列
- JavaScript中不能作为变量名的关键字和保留字总结
- python零基础学起
- 深入解析Windows窗口创建和消息分发
- 小M开发_框架MyBatis_day0724
- 总结HTML和css以及JavaScript的注释方式,并说明注释的作用
- NYOJ 733 万圣节派对
- 深入浅出
- 会话管理