题意:左右各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)的更多相关文章

  1. hdu----(1950)Bridging signals(最长递增子序列 (LIS) )

    Bridging signals Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. POJ 1631 Bridging signals (LIS:最长上升子序列)

    题意:给你一个长为n(n<=40000)的整数序列, 要你求出该序列的最长上升子序列LIS. 思路:要求(nlogn)解法 令g[i]==x表示当前遍历到的长度为i的所有最长上升子序列中的最小序 ...

  3. Poj 1631 Bridging signals(二分+DP 解 LIS)

    题意:题目很难懂,题意很简单,求最长递增子序列LIS. 分析:本题的最大数据40000,多个case.用基础的O(N^2)动态规划求解是超时,采用O(n*log2n)的二分查找加速的改进型DP后AC了 ...

  4. poj 1631 Bridging signals (二分||DP||最长递增子序列)

    Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9234   Accepted: 5037 ...

  5. POJ 1631 Bridging signals DP(最长上升子序列)

    最近一直在做<挑战程序设计竞赛>的练习题,感觉好多经典的题,都值得记录. 题意:给你t组数据,每组数组有n个数字,求每组的最长上升子序列的长度. 思路:由于n最大为40000,所以n*n的 ...

  6. OpenJudge/Poj 1631 Bridging signals

    1.链接地址: http://poj.org/problem?id=1631 http://bailian.openjudge.cn/practice/1631 2.题目: Bridging sign ...

  7. POJ 1631 Bridging signals(LIS O(nlogn)算法)

    Bridging signals Description 'Oh no, they've done it again', cries the chief designer at the Waferla ...

  8. POJ 1631 Bridging signals

    Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9441   Accepted: 5166 ...

  9. POJ 1631 Bridging signals & 2533 Longest Ordered Subsequence

    两个都是最长上升子序列,所以就放一起了 1631 因为长度为40000,所以要用O(nlogn)的算法,其实就是另用一个数组c来存储当前最长子序列每一位的最小值,然后二分查找当前值在其中的位置:如果当 ...

随机推荐

  1. Linux-hosts

    Linux-hosts hosts文件 /etc/hosts OS hosts (path) 使其生效,命令行执行 Windows (C:\Windows\System32\drivers\etc\h ...

  2. Day7 - A - Visible Lattice Points POJ - 3090

    A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), othe ...

  3. js加密(十二)yy.com rsa

    1. url: https://aq.yy.com/ 2. target: 登录js 3. 是一个简单的rsa加密,找到加密的js文件,全部复制出来,修改一下就好. 4. 和网页中的一样

  4. centos7创建ssh公钥

    步骤1:使用ssh-keygen命令创建公钥和私钥 [root@model /]# [root@model /]# ssh-keygen -t rsa -P '' Generating public/ ...

  5. JAVA 使用模板创建DOCX文档)(XDocService 使用报错条数过多报错链接不上服务器)

    详细解释https://xdoc.iteye.com/blog/2399451 https://xdoc.iteye.com/  导入 XDocService.jar   我说一下我遇到的问题 我从数 ...

  6. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-th-list

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  7. 04 MySQL数据类型

    MySQL支持的数据类型   1.数值类型:       a.整数类型    TINYINT 1字节 有符号(-128~127); 无符号(0~255) SMALLINT 2字节  有符号(-3276 ...

  8. Acwing199 余数之和

    原题面:https://www.acwing.com/problem/content/201/ 题目大意:给出正整数n和k,计算j(n, k)=k mod 1 + k mod 2 + k mod 3 ...

  9. Web基础之Spring MVC

    Spring MVC Spring MVC 说是框架,对Tomcat来说其实就是一个Servlet,关于如何从上古时期的Servlet演化到如今的SpringMVC的,可以看看这篇博文:Spring ...

  10. 云时代架构阅读笔记七——Java多线程中如何使用synchronized关键字

    关于线程的同步,可以使用synchronized关键字,或者是使用JDK 5中提供的java.util.concurrent.lock包中的Lock对象.本文探讨synchronized关键字. sy ...