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 ...
随机推荐
- C++----练习--string 从文件中一个一个单词的读直到文件尾
从文件中读取单词.并每行显示一个: 1. #include<iostream> #include<string> #include<vector> int main ...
- C++----练习--while求和
1.完成1+2+3+...+99+100 #include<iostream> int main() { std::cout<<"本程序完成1 + 2 + 3 ... ...
- Codeforces 494B Obsessive String
http://www.codeforces.com/problemset/problem/494/B 题意:给出两个串S,T,求有几种将S分成若干个子串,满足T都是这若干个子串的子串. 思路:f[n] ...
- Fedora15下搭建QT开发环境及编译QT
看了不少linux上编译qt的文章,实际上直接通过yum 安装qt是最方便的,请参考<yum安装qt> 不过初步接触fedora,为了了解一下如何在linux上编译.安装开源代码,所以必须 ...
- Shell变量替换,命令替换,转义字符
如果表达式中包含特殊字符,Shell 将会进行替换.例如,在双引号中使用变量就是一种替换,转义字符也是一种替换. 举个例子: #!/bin/bash a=10 echo -e "Value ...
- 开源欣赏wordpress之post.php
switch($action) { case 'postajaxpost': case 'post': case 'post-quickpress-publish': case 'post-quick ...
- arm linux中添加开机启动
微处理器:S5PV210操作系统:linux3.0.8 前言: 在产品中,基本上都要屏蔽arm开发板中linux系统的对外通信,只应该通过产品的相关APP做相关操作. 因此需要把该APP添 ...
- JavaScript prototype.js提升JavaScript开发效率
参考链接:http://www.yiibai.com/prototype/ Prototype提供主要方法类别: Prototype概述 Prototype实用功能 Prototype实用方法 Pro ...
- Longest Substring Without Repeating Characters 解答
Question Given a string, find the length of the longest substring without repeating characters. For ...
- Rightmost Digit(快速幂+数学知识OR位运算) 分类: 数学 2015-07-03 14:56 4人阅读 评论(0) 收藏
C - Rightmost Digit Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...