POJ - 1631 Bridging signals(最长上升子序列---LIS)
题意:左右各n个端口,已知n组线路,要求切除最少的线路,使剩下的线路各不相交,按照左端口递增的顺序输入。
分析:
1、设左端口为l,右端口为r,因为左端口递增输入,l[i] < l[j](i < j),因此若要不相交,r[i] < r[j],由此可以得出,只要求出对应的右端口序列的最长上升子序列的长度即可。
2、最长上升子序列:
dp[i]---长度为i+1的上升子序列中末尾元素的最小值(若不存在,则为INT_INF)。
如果子序列长度相同,那么最末位元素较小的在之后会更加有优势。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {0, -1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 40000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int dp[MAXN];
int a[MAXN];
int main(){
int T;
scanf("%d", &T);
while(T--){
int n;
scanf("%d", &n);
for(int i = 0; i < n; ++i){
scanf("%d", &a[i]);
}
memset(dp, INT_INF, sizeof dp);
for(int i = 0; i < n; ++i){
*lower_bound(dp, dp + n, a[i]) = a[i];
}
printf("%d\n", lower_bound(dp, dp + n, INT_INF) - dp);
}
return 0;
}
POJ - 1631 Bridging signals(最长上升子序列---LIS)的更多相关文章
- hdu----(1950)Bridging signals(最长递增子序列 (LIS) )
		
Bridging signals Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
 - POJ 1631 Bridging signals (LIS:最长上升子序列)
		
题意:给你一个长为n(n<=40000)的整数序列, 要你求出该序列的最长上升子序列LIS. 思路:要求(nlogn)解法 令g[i]==x表示当前遍历到的长度为i的所有最长上升子序列中的最小序 ...
 - Poj 1631 Bridging signals(二分+DP 解 LIS)
		
题意:题目很难懂,题意很简单,求最长递增子序列LIS. 分析:本题的最大数据40000,多个case.用基础的O(N^2)动态规划求解是超时,采用O(n*log2n)的二分查找加速的改进型DP后AC了 ...
 - poj 1631 Bridging signals (二分||DP||最长递增子序列)
		
Bridging signals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9234 Accepted: 5037 ...
 - POJ 1631 Bridging signals DP(最长上升子序列)
		
最近一直在做<挑战程序设计竞赛>的练习题,感觉好多经典的题,都值得记录. 题意:给你t组数据,每组数组有n个数字,求每组的最长上升子序列的长度. 思路:由于n最大为40000,所以n*n的 ...
 - 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(LIS  O(nlogn)算法)
		
Bridging signals Description 'Oh no, they've done it again', cries the chief designer at the Waferla ...
 - POJ 1631 Bridging signals
		
Bridging signals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9441 Accepted: 5166 ...
 - POJ 1631 Bridging signals & 2533 Longest Ordered Subsequence
		
两个都是最长上升子序列,所以就放一起了 1631 因为长度为40000,所以要用O(nlogn)的算法,其实就是另用一个数组c来存储当前最长子序列每一位的最小值,然后二分查找当前值在其中的位置:如果当 ...
 
随机推荐
- GNS3 ProxyArp(查看路由器是否具有转发功能)
			
R2是否可以把R1的数据转发出去,参看http://www.cnblogs.com/qq76211822/p/5129134.html 命令:show ip interface f0/0
 - f_lseek
			
我在STM32中移植了fatfs文件系统,实现在SD卡对文件的读写.在普通读写中都没有问题,但是一旦我关闭文件系统,再次打开读写,之前写的数据就被覆盖.比如举个例子: u8 tx_buff ...
 - Java8 使用LocalDate计算两个日期间隔多少年,多少月,多少天
			
最近项目遇到一个需要计算两个日期间隔的期限,需要计算出,整年整月整日这样符合日常习惯的说法,利用之前的Date和Calendar类会有点复杂,刚好项目使用了JDK8,那就利用起来这个新特性,上代码: ...
 - java.jvm调优
			
_amazing~ 基本: 整理:
 - c语言查漏补缺
			
getchar:执行getchar()函数时,首先从输入缓存区读取字符,直到输入缓存区为空时才等待从键盘继续输入.scanf()之间不要有printf操作. 逗号表达式 a= (++a,1,2),只取 ...
 - imp.load_source的用法
			
imp.load_source(name,pathname[,file])的作用把源文件pathname导入到name模块中,name可以是自定义的名字或者内置的模块名称. 假设在路径E:/Code/ ...
 - 吴裕雄--天生自然java开发常用类库学习笔记:Iterator接口
			
import java.util.List ; import java.util.ArrayList ; import java.util.Iterator ; public class Iterat ...
 - HDU - 6152 Friend-Graph(暴力)
			
题意:给定n个人的关系,若存在三个及以上的人两两友好或两两不友好,则"Bad Team!",否则"Great Team!". 分析:3000*3000内存100 ...
 - linux解决端口冲突问题
			
# 查看9000这个端口是否被使用 netstat -lnt | grep 9000 -l 显示正在被监听(listen)的端口 -n 表示直接显示端口数字 -t 表示的 ...
 - JavaScript.descriptor(属性描述符)
			
属性描述符是对JavaScript属性的描述,包括:value.writable.enumerable.configurable,除value其他默认为true. 本文包括: 取得属性描述符. Obj ...