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 ...
随机推荐
- full-background.js
$(window).on('load', function () { $(window).trigger('resize'); }); $(function () { var $window = $( ...
- thinkphp使用模块/控制器/操作访问时出现No input file specified.解决方式
thinkphp使用 http://serverName/index.php/模块/控制器/操作 访问时,出现了 No input file specified. 的错误 解决办法: 一: 开启cgi ...
- 理解JMS规范中消息的传输模式和消息持久化
http://blog.csdn.net/aitangyong/article/category/2175061 http://blog.csdn.net/aitangyong/article/det ...
- Unix/Linux环境C编程入门教程(38) shell命令进阶演示
1.w命令 该命令也可以查看登录当前系统的用户信息.与who命令相比,w命令的功能更强大,它不但可以显示当前有哪些用户登录到系统,还可以显示这些用户正在进行的操作,并给出更加详细和科学的统计数据 ...
- poj 1753 Flip Game(bfs状态压缩 或 dfs枚举)
Description Flip game squares. One side of each piece is white and the other one is black and each p ...
- #include<string.h>
#include<string.h> 1 strcpy #include <string.h> char *strcpy(char *str1, const char *str ...
- javax.mail用smtp服务器发送带附件的邮件
jar包: javax.mail-1.5.5.jar maven配置: <dependency> <groupId>com.sun.mail</groupId> & ...
- FlashBack-SCN-TIMESTAMP
一.基于时间(as of timestamp)的flashback1.创建表create table flash_tab(id,vl) as select rownum,oname from ( se ...
- linux 能访问内网,但不能访问外网?解决方案
用iptables就可以了 iptables -F iptables -t nat -F iptables -A INPUT -s -d -j ACCEPT iptables -A INPUT -d ...
- Echarts动态数据显示
自己慢慢摸索出来的,留着以后可能会用到 一.先引入jquery,再引入echarts.js 二.配置容器 三.配置路径和数据选项等 <script type="text/javascr ...