职务地址:HDU 1950

这题是求最长上升序列,可是普通的最长上升序列求法时间复杂度是O(n*n)。显然会超时。于是便学了一种O(n*logn)的方法。也非常好理解。

感觉还用到了一点贪心的思想。

详细的见这篇博客吧,写的非常通俗易懂。传送门

代码例如以下:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
#define LL long long
int a[50000], b[50000], len;
int bin_seach(int x)
{
int low=1, high=len, mid, ans;
while(low<=high)
{
mid=low+high>>1;
if(b[mid]>=x) {high=mid-1;ans=mid;}
else low=mid+1;
}
return ans;
}
int main()
{
int t, n, i, pos;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
len=0;
b[++len]=a[0];
for(i=1;i<n;i++)
{
if(a[i]>b[len])
{
b[++len]=a[i];
}
else
{
pos=bin_seach(a[i]);
b[pos]=a[i];
}
}
printf("%d\n",len);
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

HDU 1950 Bridging signals (DP)的更多相关文章

  1. HDU 1950 Bridging signals【最长上升序列】

    解题思路:题目给出的描述就是一种求最长上升子序列的方法 将该列数an与其按升序排好序后的an'求出最长公共子序列就是最长上升子序列 但是这道题用这种方法是会超时的,用滚动数组优化也超时, 下面是网上找 ...

  2. hdu 1950 Bridging signals 求最长子序列 ( 二分模板 )

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

  3. HDU 1950 Bridging signals

    那么一大篇的题目描述还真是吓人. 仔细一读其实就是一个LIS,还无任何变形. 刚刚学会了个二分优化的DP,1A无压力. //#define LOCAL #include <iostream> ...

  4. HDU 1950 Bridging signals(LIS)

    最长上升子序列(LIS)的典型变形,O(n^2)的动归会超时.LIS问题可以优化为nlogn的算法. 定义d[k]:长度为k的上升子序列的最末元素,若有多个长度为k的上升子序列,则记录最小的那个最末元 ...

  5. HDU 1950 Bridging signals (LIS,O(nlogn))

    题意: 给一个数字序列,要求找到LIS,输出其长度. 思路: 扫一遍+二分,复杂度O(nlogn),空间复杂度O(n). 具体方法:增加一个数组,用d[i]表示长度为 i 的递增子序列的最后一个元素, ...

  6. hdoj 1950 Bridging signals【二分求最大上升子序列长度】【LIS】

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

  7. (hdu)1950 Bridging signals(最长上升子序列)

    Problem Description 'Oh no, they've done it again', cries the chief designer at the Waferland chip f ...

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

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

  9. HDU 1950(LIS)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1950 Bridging signals Time Limit: 5000/1000 MS (Java ...

随机推荐

  1. 基于HttpClient 4.3的可訪问自签名HTTPS网站的新版工具类

    本文出处:http://blog.csdn.net/chaijunkun/article/details/40145685,转载请注明.因为本人不定期会整理相关博文,会对相应内容作出完好.因此强烈建议 ...

  2. Wake-On-LAN待机或休眠模式中唤醒

    Wake-On-LAN简称WOL,是一种电源管理功能:如果存在网络活动,则允许设备将操作系统从待机或休眠模式中唤醒.许多主板厂商支持IBM提出的网络唤醒标准.该标准允许网络管理员远程打开PC机电源,以 ...

  3. 讨论UML概念和模型UML九种图。

    文件夹: UML的视图 UML的九种图 UML中类间的关系 上文我们介绍了,UML的视图.在每一种视图中都包括一个或多种图. 本文我们重点解说UML每种图的细节问题: 1.用例图(use case d ...

  4. 隐马尔科夫模型(HMM)及事实上现

    马尔科夫模型 马尔科夫模型是单重随机过程,是一个2元组:(S,A). 当中S是状态集合,A是状态转移矩阵. 仅仅用状态转移来描写叙述随机过程. 马尔科夫模型的2个如果 有限历史性如果:t+l时刻系统状 ...

  5. 使用Socket沟通

    当两台电脑TCP/IP协议进行通讯.平时Socket对象来表示该通信接口的两端,并通过Socket生产I/O流进行网络通信. 其中ServerSocket对象可以接收从连接的其他通信实体的请求.这个目 ...

  6. Shine we together: A innovative dating site using 2012 Nobel Laureate Roth's algorithm

    Abstract Our dating site introduced scoring and its related functionalities innovatively, conforming ...

  7. 关于js中window.location.href,location.href,parent.location.href,top.location.href的使用方法

    关于js中"window.location.href"."location.href"."parent.location.href".&qu ...

  8. 在深入分析:Android在app之间的相互作用(一个,使用Action)

    我们开发Android App时间应用,有些需求,我们需要启动另一App为了应对一些逻辑.例如,我们需要映射基于地址调用系统或相关Map App,所以,我们不自己有App在相应的功能的制备.而是通过I ...

  9. effective c++ 条款18 make interface easy to use correctly and hard to use incorrectly

    举一个容易犯错的例子 class Date { private: int month; int day; int year; public: Date(int month,int day,int ye ...

  10. 达到J2EE在后台action控制接待javascript弹出的对话框

    1.后台Action于: request.setAttribute("message", "这项username要么password错误,请重新输入!"); 2 ...