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 ...
随机推荐
- 深入理解计算机系统第二版习题解答CSAPP 2.16
填写下表,说明不同移位运算对单字节数的影响. x x<<3 x>>2(逻辑) x>>2(算术) 十六进制 二进制 二进制 十六进制 二进制 十六进制 二进制 十六进 ...
- mysql数据库常用语句3
一:查询指定数据库中所有的表名 数据库名:test select table_name from information_schema.tables where table_schema='test' ...
- 有关于Algorithm的基础介绍
Niklaus Wirth:Algorithm + Data Structures = Programs 这句话呢,觉得很正确,算法和程序是不同的概念,算法的思想呢有递推,枚举,分治,贪婪,试探法,模 ...
- B/S一些小知识及常用控件
一: B/S网页的运行 页面在设计的时候,本身就是一个类.在运行的时间,是一个对象. 其中aspx和aspx.cs是在同一个类下. aspx是主要是负责界面,而aspx.cs主要是负责数据逻辑. 呈现 ...
- JavaScript高级程序设计(第三版)学习笔记8、9、10章
第8章,BOM BOM的核心对象是window,具有双重角色,既是js访问浏览器的一个接口,又是ECMAScript规定的Global对象.因此,在全局作用域中声明的函数.变量都会变成window对象 ...
- spark处理jsonFile
按照spark的说法,这里的jsonFile是特殊的文件: Note that the file that is offered as jsonFile is not a typical JSON f ...
- ASP.NET Web Service如何工作(3)
ASP.NET Web Service如何工作(3) [日期:2003-06-26] 来源:CSDN 作者:sunnyzhao(翻译) [字体:大 中 小] 为了使.asmx句柄有可能反串行化SOA ...
- 修改placeholder颜色
#contact_info为textarea的ID #contact_info::-webkit-input-placeholder{ color:#999;}#contact_info:-moz-p ...
- NSDate与 NSString 、long long类型的相互转化
我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3560280.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体验 ...
- 重构if...else...或者switch程序块 为 中介者(Mediator)模式.的思考
http://www.cnblogs.com/insus/p/4142264.html 重构if...else...或者switch程序块 为 中介者(Mediator)模式.的思考 首先普世的编程架 ...