DP:Bridging Signals(POJ 1631)

(这一题的难度在于读题)题目大意:有一堆引脚(signals),左边一排,右边一排,左边从上到下,对应着连接右边的引脚(所有的引脚都被接上),现在引脚之间的连线有交叉,我们要桥接这些交叉,而桥接是费事的,现在要你求不交叉引脚的最大数目
明白题在说什么以后,是不是感觉豁然开朗?
没错,这一题我们只用把左边的引脚从上到下排列(事实上已经排了),然后看右边对应的引脚的上升序最长有多少就可以了
昨天我弄了一个Wooden Sticks,这一题也要用到LIS,而且还是直接用LIS,更简单
#include <iostream>
#include <functional>
#include <algorithm> using namespace std;
typedef int Position; static int ports[];
static int stacks[]; void Search(const int);
Position Binary_Search(const int,const int); int main(void)
{
int case_sum, ports_sum;
while (~scanf("%d", &case_sum))
{
for (int j = ; j < case_sum; j++)
{
scanf("%d", &ports_sum);
for (int i = ; i < ports_sum; i++)
scanf("%d", &ports[i]);//左边的每一个点对应右边的拿一个点
Search(ports_sum);
}
}
return ;
} Position Binary_Search(const int len,const int item)
{
int left = , right = len, mid; while (left <= right && left != len)
{
mid = (left + right) / ;
if (item < stacks[mid])
right = mid - ;
else
left = mid + ;
}
return left;
} void Search(const int ports_sum)
{
int pos;
int length = ; stacks[] = ports[]; for (int i = ; i < ports_sum; i++)
{
pos = Binary_Search(length,ports[i]); stacks[pos] = ports[i];
if (pos == length)
length++;
}
printf("%d\n", length);
}

DP:Bridging Signals(POJ 1631)的更多相关文章
- poj 1631 Bridging signals (二分||DP||最长递增子序列)
Bridging signals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9234 Accepted: 5037 ...
- 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(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 ...
- Bridging signals(二分 二分+stl dp)
欢迎参加——每周六晚的BestCoder(有米!) Bridging signals Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 6 ...
- hdu----(1950)Bridging signals(最长递增子序列 (LIS) )
Bridging signals Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- B - Bridging signals (LIS)
点击打开链接 B - Bridging signals 'Oh no, they've done it again', cries the chief designer at the Waferlan ...
- hdoj 1950 Bridging signals【二分求最大上升子序列长度】【LIS】
Bridging signals Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- Java NIO、NIO.2学习笔记
相关学习资料 http://www.molotang.com/articles/903.html http://www.ibm.com/developerworks/cn/education/java ...
- 代码重构-4 通用方法 用 static
只要没有用到 this.变量/方法 的,都可以用static 原代码: private string GetPeriodDesc(int lotteryPeriod) { return EnumHe ...
- 使用PPA在Ubuntu上安装php5.4~5.6,7
使用PPA在Ubuntu上安装php5.4~5.6,7 sudo apt-get install software-properties-common sudo add-apt-repository ...
- 操作haproxy配置文件教师版
作用: 可查,可增,可删,可修改 #_*_coding:utf-8_*_ import os def file_handle(filename,backend_data,record_list=Non ...
- 只能输入汉字js脚本
<html> <head> <meta http-equiv="Content-Type" content="text/html" ...
- IIS 7.5 配置10W高并发
原文: http://www.myhack58.com/Article/sort099/sort0100/2012/35585.htm 原文: http://www.myhack58.com ...
- Socket网络编程(1)
TCP/IP 简单介绍 应用层 (Application):应用层是个很广泛的概念,有一些基本相同的系统级 TCP/IP 应用以及应用协议,也有许多的企业商业应用和互联网应用. 传输层 (Transp ...
- linux find 命令详解
Linux下 利用find命令删除所有vssver2.scc文件 删除所有vssver2.scc文件 这是我当初查找 Linux find 命令的目的所在 1) find / -name ‘vssv ...
- 优化MySQL,还是使用缓存?读一篇文章有感
今天我想对一个Greenfield项目上可以采用的各种性能优化策略作个对比.换言之,该项目没有之前决策强加给它的各种约束限制,也还没有被优化过. 具体来说,我想比较的两种优化策略是优化MySQL和缓存 ...
- Entity Framework CodeFirst尝试
前言 Code First模式我们称之为“代码优先”模式,是从EF4.1开始新建加入的功能.使用Code First模式进行EF开发时开发人员只需要编写对应的数据类(其实就是领域模型的实现过程),然后 ...