poj 1631 Bridging signals (二分||DP||最长递增子序列)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 9234 | Accepted: 5037 |
Description
A typical situation is schematically depicted in figure 1. The ports of the two functional blocks are numbered from 1 to p, from top to bottom. The signal mapping is described by a permutation of the numbers 1 to p in the form of a list of p unique numbers in the range 1 to p, in which the i:th number specifies which port on the right side should be connected to the i:th port on the left side.Two signals cross if and only if the straight lines connecting the two ports of each pair do.Input
Output
Sample Input
4
6
4
2
6
3
1
5
10
2
3
4
5
6
7
8
9
10
1
8
8
7
6
5
4
3
2
1
9
5
8
9
2
3
1
7
4
6
Sample Output
3
9
1
4
思路:
最长递增子序列: (二分)代码:
#include<iostream>
#include<stdio.h>
int arr[]; int search(int a,int b,int n){ //二分
int mid;
while(a<=b){
mid = (a+b)/;
if(n>arr[mid]){
a = mid + ;
}else{
b = mid - ;
}
}
return b;
} int main(){
int t;
scanf("%d",&t);
while(t--){
int n,i;
scanf("%d",&n);
scanf("%d",&arr[]);
int pos=;
for(i=;i<n;i++){
scanf("%d",&arr[pos]);
if(arr[pos]>=arr[pos-]){ //比当前的数大的话插在后面
pos++;
}else{ //如果小的话在前面找到合适的位置插入
int m = search(,pos-,arr[pos]);
arr[m+]=arr[pos];
}
}
printf("%d\n",pos);
}
return ;
}
poj 1631 Bridging signals (二分||DP||最长递增子序列)的更多相关文章
- Poj 1631 Bridging signals(二分+DP 解 LIS)
题意:题目很难懂,题意很简单,求最长递增子序列LIS. 分析:本题的最大数据40000,多个case.用基础的O(N^2)动态规划求解是超时,采用O(n*log2n)的二分查找加速的改进型DP后AC了 ...
- Luogu 3402 最长公共子序列(二分,最长递增子序列)
Luogu 3402 最长公共子序列(二分,最长递增子序列) Description 经过长时间的摸索和练习,DJL终于学会了怎么求LCS.Johann感觉DJL孺子可教,就给他布置了一个课后作业: ...
- [DP]最长递增子序列
#include <iostream> #include <limits.h> #include <vector> #include <algorithm&g ...
- HDU-1160-FatMouse's Speed(DP, 最长递增子序列)
链接: https://vjudge.net/problem/HDU-1160 题意: FatMouse believes that the fatter a mouse is, the faster ...
- POJ 1631 Bridging signals DP(最长上升子序列)
最近一直在做<挑战程序设计竞赛>的练习题,感觉好多经典的题,都值得记录. 题意:给你t组数据,每组数组有n个数字,求每组的最长上升子序列的长度. 思路:由于n最大为40000,所以n*n的 ...
- POJ - 1631 Bridging signals(最长上升子序列---LIS)
题意:左右各n个端口,已知n组线路,要求切除最少的线路,使剩下的线路各不相交,按照左端口递增的顺序输入. 分析: 1.设左端口为l,右端口为r,因为左端口递增输入,l[i] < l[j](i & ...
- POJ 1631 Bridging signals (LIS:最长上升子序列)
题意:给你一个长为n(n<=40000)的整数序列, 要你求出该序列的最长上升子序列LIS. 思路:要求(nlogn)解法 令g[i]==x表示当前遍历到的长度为i的所有最长上升子序列中的最小序 ...
- 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 ...
随机推荐
- iptables配置说明
1.iptables的发展: 对于TCP/IP的七层模型来讲,我们知道第三层是网络层,三层的防火墙会在这层对源地址和目标地址进行检测.iptables是网络层的防火墙. iptables的前身叫 ...
- Javascript中new
// 加不加new结果都一样 var obj = new Function('var temp = 100;this.temp = 200;return temp + this.temp;'); al ...
- dos下循环复制一张图片的bat
@echo off setlocal enabledelayedexpansion ,,) do ( @echo !dm! copy .png !dm!.png ) 我期待的结果是将140041.pn ...
- media type和media query
media type media type是CSS2的重要属性,通过它,可以针对不同的设备指定不同的样式. media type种类: 用法: <link href="styl ...
- 正则表达式 自学笔记整理记录 EASY REGEX~
整理正则表达式篇 -wuian7yulian 基础知识介绍 : 1> 字符串的组成: 对于字符串"ABC"来说,其包 ...
- 项目开发笔记-传单下发 名片替换 文件复制上传/html静态内容替换/json解析/html解析
//////////////////////////// 注意: 此博客是个人工作笔记 非独立demo////////////////////////////////// .............. ...
- div中的img垂直居中
<html> <head> <style type="text/css"> .imgDiv { overflow: hidden; displa ...
- linux gpg 使用笔记
http://linux.chinaunix.net/techdoc/system/2009/04/30/1109541.shtml 一.GnuPG的简介 我们在网上的发送的邮件是明文的,可以 ...
- 支持BLOB操作的Jena框架扩展——JenaBLOB
与研究语义网的同行们分享一下上半年做的一个东西,它是支持BLOB操作的Jena框架扩展--JenaBLOB,已在GitHub上开源,欢迎提出宝贵意见! 众所周知,Jena是不支持BLOB类型的Lite ...
- Delphi - 在ListView中添加一个进度条
// 相关定义 Type TListData = Record FileName: String; Percent: Integer; End; PListData = ^TListData; // ...