hdu-5532 Almost Sorted Array(最长单调不xx序列)
来源:互联网 发布:手机淘宝联盟几号提现 编辑:程序博客网 时间:2024/06/09 19:05
题目来源:http://acm.hdu.edu.cn/php?pid=5532
题意
定义一个序列若是最多删去一个数字,能够使得这个序列成为有序序列,那么原序列被叫做almost sorted。
思路
额,这道题,眼看着大牛分分钟A了,可我依旧是迷茫,拿着草稿纸急急忙忙的画着序列,左推右推,终于发现了一丝端倪,发现这道题就是一个裸的LIS,但是又由于手残,忙着上课。。。
使用nlogn的时间复杂度,用二分写单调非递减子序列,最后把原序列反过来在来一次。
代码
#include<cmath>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[100000+10];int dp1[100000+10];int dp2[100000+10];int main(){ int T; scanf("%d",&T); while(T--) { int n,len=1; scanf("%d",&n); for(int i=0; i<n; i++) scanf("%d",&a[i]); dp1[1]=a[0]; for(int i=1; i<n; i++) { if(a[i]>=dp1[len]) dp1[++len]=a[i]; else { int pos=upper_bound(dp1+1,dp1+len+1,a[i])-dp1; dp1[pos] = a[i]; } } int maxx=len; for(int i=0;i<n/2;i++) { swap(a[i],a[n-i-1]); } dp2[1]=a[0]; len=1; for(int i=1; i<n; i++) { if(a[i]>=dp2[len]) dp2[++len]=a[i]; else { int pos=upper_bound(dp2+1,dp2+len+1,a[i])-dp2; dp2[pos]=a[i]; } } if(len>maxx) maxx=len; if(n-maxx<=1) printf("YES\n"); else printf("NO\n"); }}
阅读全文
0 0
- hdu-5532 Almost Sorted Array(最长单调不xx序列)
- HDU 5532 Almost Sorted Array(最长不下降子序列nlogn模板)
- hdu 5532 Almost Sorted Array(最长上升(不下降)子序列和最长下降(不上升)子序列)
- 简单dp hdu 5532 Almost Sorted Array nlogn 的最长非严格单调子序列
- Almost Sorted Array(HDU 5532 单调递增子序列)
- hdu 5532 Almost Sorted Array(最长不上升子序列、暴力)
- hdu 5532 Almost Sorted Array 最长上升子序列
- HDU 5532 Almost Sorted Array(思维,最长递增子序列,模拟)
- [hdu 5532] [2015ACM/ICPC亚洲区长春站 ] Almost Sorted Array 最长不下降子序列
- HDU5532 Almost Sorted Array(最长不上升子序列)
- HDU5532 Almost Sorted Array(最长子序列)
- hdu 5532 Almost Sorted Array(LIS)
- 【HDU】5532 - Almost Sorted Array(LIS)
- HDU-5532 Almost Sorted Array(LIS)
- HDU 5532 Almost Sorted Array(LIS)
- hdu 5532 Almost Sorted Array
- HDU 5532 Almost Sorted Array
- HDU 5532 Almost Sorted Array
- struts2是单例的吗
- MMORPG服务器架构
- mysql DDL DML
- 并发新特性—阻塞队列和阻塞栈
- C头文件编写基本规则
- hdu-5532 Almost Sorted Array(最长单调不xx序列)
- 夜间模式
- typedef的学习 数组指针与指针数组的差异
- githubdesktop入门(一):入门及单人项目创建及删除
- 追踪 Netty 异常占用堆外内存的经验分享
- bzoj 4999: This Problem Is Too Simple! 树链剖分+线段树
- 基于CentOS7.3安装Zabbix3.2手记
- pandas读取csv文件
- HDU 1036 Average is not Fast Enough! (水题)