POJ 1631 Bridging signals & 2533 Longest Ordered Subsequence
两个都是最长上升子序列,所以就放一起了
1631 因为长度为40000,所以要用O(nlogn)的算法,其实就是另用一个数组c来存储当前最长子序列每一位的最小值,然后二分查找当前值在其中的位置;如果当前点不能作为当前最长子序列的最大值,则更新找到值为两者间的较小值。
2533 就是一个裸的最长上升子序列。。。这里就不多说了,直接dp就好。。。
1611:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define maxn 100005
using namespace std; int d;
int c[maxn]; int erfen (int d,int n){
int l=,r=n;
int mid;mid=(l+r)/;
while (l<r){
if (c[mid]<d&&c[mid+]>=d) return mid+;
if (c[mid]>d)
r=mid;
else l=mid+;
mid=(l+r)/;
}
return mid;
} int main (){
int n;
int t;
scanf ("%d",&t);
while (t--){
scanf ("%d",&n);
int ans=;
memset (c,,sizeof c);
for (int i=;i<n;i++){
scanf ("%d",&d);
int x=erfen (d,ans);//cout<<x;
if (x>=ans&&c[ans]<d)
c[ans++]=d;
else if (c[x]!=d) c[x]=d;
}
printf ("%d\n",ans-);
}
return ;
}
2533:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define maxn 1005
using namespace std; int d[maxn],dp[maxn]; int main (){
int n;
while (~scanf ("%d",&n)){
for (int i=;i<n;i++)
scanf ("%d",&d[i]);
int ans=;
for (int i=;i<n;i++){
dp[i]=;
for (int j=;j<i;j++){
if (d[j]<d[i])
dp[i]=max (dp[i],dp[j]+);
}
ans=max (ans,dp[i]);
}
printf ("%d\n",ans);
}
return ;
}
POJ 1631 Bridging signals & 2533 Longest Ordered Subsequence的更多相关文章
- POJ 2533 Longest Ordered Subsequence(裸LIS)
传送门: http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 6 ...
- poj 2533 Longest Ordered Subsequence 最长递增子序列
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098562.html 题目链接:poj 2533 Longest Ordered Subse ...
- POJ 2533 Longest Ordered Subsequence(LIS模版题)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 47465 Acc ...
- POJ 2533 - Longest Ordered Subsequence - [最长递增子序列长度][LIS问题]
题目链接:http://poj.org/problem?id=2533 Time Limit: 2000MS Memory Limit: 65536K Description A numeric se ...
- POJ 2533 Longest Ordered Subsequence(最长上升子序列(NlogN)
传送门 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subseque ...
- POJ 2533 Longest Ordered Subsequence 最长递增序列
Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...
- poj 2533 Longest Ordered Subsequence(LIS)
Description A numeric sequence of ai is ordered ifa1 <a2 < ... < aN. Let the subsequence of ...
- POJ 2533 Longest Ordered Subsequence(DP 最长上升子序列)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 38980 Acc ...
- Poj 2533 Longest Ordered Subsequence(LIS)
一.Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...
随机推荐
- shell date格式化输出
1- echo `date "+%Y-%m-%d %H:%M:%S"` 2014-11-13 15:06:26 2- echo `date "+%y-%m-%d %H ...
- 关于Mysql不能被远程连接的问题
1.修改mysql配置文件 注释掉 #bind_address:127.0.0.1 2.授权账户远程连接权限 grant all priveleges on '.' To 'myuser'@'%' ...
- ini_set()注意要点和解决方法
在php编程中,很多情况下,我们不希望通过修改配置文件(php.ini)来实现相关功能,这样不利于代码的可移植性. 大多数情况下,我们会使用ini_set()来实现配置文件的占时修改.但需要注意的是, ...
- ASP.NET用户自定义控件配置
一直以来开发中碰到要写自定义控件的时候总是习惯性的找度娘,而没有自己记住,结果今天就悲剧了,找了半天才找到,想想还是自己积累起来吧! 第一种配置方式: 配置写在webconfig文件中,位置如下: w ...
- C 宏定义
C/C++中宏使用总结 .C/C++中宏总结C程序的源代码中可包括各种编译指令,这些指令称为预处理命令.虽然它们实际上不是C语言的一部分,但却扩展了C程序设计的环境.本节将介绍如何应用预处理程序和注释 ...
- 序列化与反序列化 - BinaryFormatter二进制(.dat)、SoapFormatter(.soap)、XmlSerializer(.xml)
序列化的作用是什么?为什么要序列化? 1.在进程下次启动时读取上次保存的对象的信息. 2.在不同的应用程序域或进程之间传递数据. 3.在分布式应用程序中的各应用程序之间传输对象. 所为序列化,就是将对 ...
- BarTender打印出来的条码与设计的不同如何处理
今日有用户在使用BarTender设计打印条码时发现自己设计出来的条码与打印显示的条码有不一样的地方,也就是BarTender模板上的条码有显示警戒栏,但打印的条码警戒栏却没了,这一问题要如何解决呢? ...
- android-读取Assets图片资源保存到SD - 随心
public class ReadBitmap { public void readByte(Context c, String name, int indexInt) { byte[] b = nu ...
- IOS设计模式学习(8)适配器
1 前言 在面向对象软件设计中,有时候我们想把有用而经过精心测试的类,用于应用程序的其他新领域.但是,新功能需要新接口,而新接口与要复用的现有类不一致的情况非常普遍.我们不想为新的接口而重写可靠的类. ...
- Android手机APN设置(中国移动 联通3G 电信天翼),解决不能上网的问题
中国移动 第一步,设置CMNET上网 新建APN 1.名称:cmnet 2.APN:cmnet 3.APN类型:default 就仅仅填写上面3个选项,其它都是默认,不用填写. 第二步,设置彩信 新建 ...