HDU 1950 Bridging signals (DP)
2024-10-15 06:15:24
职务地址: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;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
最新文章
- JSON.parse与eval的区别
- win7配置ftp服务
- a questions
- oracle 特殊符号
- C#深入浅出 C#语法中的重中之重——委托(四)
- codeforce 600C - Make Palindrome
- jQuery Validate验证框架使用
- Unity3d fur真实毛发渲染
- Ubuntu12.04 下svn服务搭建及Windows客户端tortoisesvn的使用
- Java web 基础
- UML示例图
- jquery中防止冒泡事件
- BotVS配置托管者-基于新浪云
- sea.js简单使用教程
- Linux性能工具图册-便于查阅
- 干货!一篇文章集合所有Linux基础命令
- MVCC(Multi-version Cocurrent Control)多版本并发控制协议
- asp.net执行顺速
- D2
- 有关自动化构建gulp的搭建