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 ...
随机推荐
- ckeditor详解
源网页编辑软件FCKEditor在09年发布更新到3.0,并改名为CKEditor.改进后的ckeditor更加模块话,配置更加灵活,和以前的fckeditor使用方式上也有所不同.在我的mvc项目中 ...
- 添加事件监听兼容IE6-8
IE8一下浏览器不支持addEventListener,用attachEvent取而代之,但是在时间类型前面要加上’on‘,例如click时间在attachEvent中要写成onclick. var ...
- Java 之String.valueOf(obj)
实例代码如下: String str = null; String uSelectDate = String.valueOf(str); System.out.println("====== ...
- HttpApplication实战大文件上传 (第四篇)
一.Asp.net中的文件上传 在Asp.net 1.1中,文件在上传过程中将被全部保存在内存中,对于大文件来说,会造成内存空间的过度使用,可能会招致恶意攻击.为了解决这个问题,Asp.net在配置文 ...
- awk 处理
find . -type f | awk '{print $NF}' | grep pdf$ |grep -v preview | while read A; do ls -ltr $A| awk ' ...
- HDU 4649 Professor Tian
Professor Tian Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) T ...
- LeetCode——Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- Oracle SQL函数之转换函数
chartorowid(c1) [功能]转换varchar2类型为rowid值 [参数]c1,字符串,长度为18的字符串,字符串必须符合rowid格式 [返回]返回rowid值 [示例] SQL> ...
- python 笔记2--函数
函数变量 >>> a = abs # 变量a指向abs函数 >>> a(-1) # 所以也可以通过a调用abs函数 1 定义函数 def my_abs(x): if ...
- android 硬件解码学习
FileInputStream in = new FileInputStream("/sdcard/sample.ts"); String mimeType = "vid ...