POJ 1631 Bridging signals(LIS的等价表述)
把左边固定,看右边,要求线不相交,编号满足单调性,其实是LIS的等价表述。
(如果编号是乱的也可以把它有序化就像Uva 10635 Prince and Princess那样
O(nlogn)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
//#include<bits/stdc++.h>
using namespace std; const int maxn = 4e4+;
int g[maxn]; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int T; cin>>T;
while(T--){
int n, ans = ; scanf("%d",&n);
for(int i = ,c = ; i < n; i++){
int x, k; scanf("%d",&x);
k = lower_bound(g+,g+c,x)-g;
ans = max(ans,k);
g[k] = x;
if(k==c) c++; //不用把辅助数组g初始化,只要维护一个下标即可
}
printf("%d\n",ans);
}
return ;
}
POJ 1631 Bridging signals(LIS的等价表述)的更多相关文章
- POJ 1631 Bridging signals (LIS:最长上升子序列)
题意:给你一个长为n(n<=40000)的整数序列, 要你求出该序列的最长上升子序列LIS. 思路:要求(nlogn)解法 令g[i]==x表示当前遍历到的长度为i的所有最长上升子序列中的最小序 ...
- POJ 1631 Bridging signals(LIS O(nlogn)算法)
Bridging signals Description 'Oh no, they've done it again', cries the chief designer at the Waferla ...
- POJ 1631 Bridging signals(LIS 二分法 高速方法)
Language: Default Bridging signals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1076 ...
- OpenJudge/Poj 1631 Bridging signals
1.链接地址: http://poj.org/problem?id=1631 http://bailian.openjudge.cn/practice/1631 2.题目: Bridging sign ...
- POJ 1631 Bridging signals
Bridging signals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9441 Accepted: 5166 ...
- poj 1631 Bridging signals (二分||DP||最长递增子序列)
Bridging signals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9234 Accepted: 5037 ...
- Poj 1631 Bridging signals(二分+DP 解 LIS)
题意:题目很难懂,题意很简单,求最长递增子序列LIS. 分析:本题的最大数据40000,多个case.用基础的O(N^2)动态规划求解是超时,采用O(n*log2n)的二分查找加速的改进型DP后AC了 ...
- POJ - 1631 Bridging signals(最长上升子序列---LIS)
题意:左右各n个端口,已知n组线路,要求切除最少的线路,使剩下的线路各不相交,按照左端口递增的顺序输入. 分析: 1.设左端口为l,右端口为r,因为左端口递增输入,l[i] < l[j](i & ...
- POJ 1631 Bridging signals & 2533 Longest Ordered Subsequence
两个都是最长上升子序列,所以就放一起了 1631 因为长度为40000,所以要用O(nlogn)的算法,其实就是另用一个数组c来存储当前最长子序列每一位的最小值,然后二分查找当前值在其中的位置:如果当 ...
随机推荐
- PTA 1045【DP】
思路: DP[ i ] 代表以值 i 结尾的当前最长长度. 每次枚举序列数组,dp[ i ] = max( dp[ i ] ,dp[ a[j] ] + 1); #include <bits/st ...
- Oracle的RBO和CBO
Oracle的优化器有两种优化方式,即基于规则的优化方式(Rule-Based Optimization,简称为RBO)和基于代价的优化方式(Cost-Based Optimization,简称为CB ...
- jsp页面将日期类型的数据转换成xxxx年xx月xx日xx时xx分
<fmt:formatDate value="${bsjz.cxkssj}" pattern="yyyy"/><span class=&quo ...
- VMware Workstation 安装以及Linux虚拟机安装 指北
最近有挺多小伙伴跟我说起虚拟机这个东西,所以,今天就给大家写一篇虚拟机安装使用指北吧. 虚拟机(英语:virtual machine),在计算机科学中的体系结构里,是指一种特殊的软件,可以在计算机平台 ...
- thinkphp5缓存使用
之前不明白缓存有什么用处,后来看了一些案例大概有点了解,记录一下.1.thinkphp5没有静态缓存2.对于一些更新不是太频繁的数据,我们可以使用缓存机制对查询到的数据进行缓存,减缓数据库压力3.下面 ...
- Java基础笔记(十)—— 数组
数组是具有相同类型的数据的集合,是一种引用数据类型,一般具有固定的长度,并且在内存中占据连续的空间. 数组声明:数据类型[ ] 数组名; 数据类型 数组名[ ]; 如:int[ ...
- 1089 Insert or Merge(25 分)
According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...
- TOMCAT调优内容
使用NIO EndPoint connector线程数, 最大并发数 最大请求数 阻塞队列大小 jvm Xms Xmm maxMetaspace gc收集器 应用app逻辑优化:这个才是重点
- 把sublime3打造成c++开发环境
安装sublime 3 sudo add-apt-repository ppa:webupd8team/sublime-text-3 sudo apt-get update sudo apt-get ...
- (转)在CentOS中修改中文字符集
虽然在实际工作环境下,Linux中不建议使用中文,但是如果一定要进行中文显示,尤其对于刚接触linux且英语基础不太好的人来说,那么本文具有一定的参考价值. 本文介绍在linux的shell环境下优化 ...