最长上升子序列o(nlongn)写法

dp[]=a[];
int len=;
for(int i=;i<=n;i++){
if(a[i]>dp[len]) dp[++len]=a[i];
else *lower_bound(dp+,dp++len,a[i])=a[i];
}

数组dp[len]描述的是长度为len时的结尾的最小元素。

怎么样才能不交叉呢?i和j相连,i1和j1想连,只有i<i1&&j<j1时才不会交叉,所以让第行单调递增,然后第而行求他的LIS

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5E5+;
const int INF=1E9+;
struct stu{
int a,b;
bool friend operator <(const stu x,const stu y){
return x.a<y.a;
}
}arr[N];
int a[N],dp[N];
int main(){
ios::sync_with_stdio();
int n;
int t=;
while(cin>>n){
for(int i=;i<=n;i++) cin>>arr[i].a>>arr[i].b;
sort(arr+,arr++n);
for(int i=;i<=n;i++){
a[i]=arr[i].b;
}
dp[]=a[];
int len=;
for(int i=;i<=n;i++){
if(a[i]>dp[len]) dp[++len]=a[i];
else *lower_bound(dp+,dp++len,a[i])=a[i];
}
cout << "Case " << ++t << ":\n";
cout << "My king, at most " << len << (len > ? " roads" : " road") << " can be built.\n\n";
}
return ;
}

注:sb了。为什么要用struct呢?还得排序,,,直接a[x]=y就行.....

最长上升子序列 HDU 1025 Constructing Roads In JGShining's Kingdom的更多相关文章

  1. HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP)

    HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP) 点我挑战题目 题目分析 题目大意就是给出两两配对的poor city和ric ...

  2. [ACM] hdu 1025 Constructing Roads In JGShining's Kingdom (最长递增子序列,lower_bound使用)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  3. HDU 1025 Constructing Roads In JGShining's Kingdom[动态规划/nlogn求最长非递减子序列]

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  4. HDU 1025 Constructing Roads In JGShining's Kingdom(二维LIS)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  5. hdu 1025:Constructing Roads In JGShining's Kingdom(DP + 二分优化)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  6. HDU 1025 Constructing Roads In JGShining's Kingdom(求最长上升子序列nlogn算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025 解题报告:先把输入按照r从小到大的顺序排个序,然后就转化成了求p的最长上升子序列问题了,当然按p ...

  7. hdu 1025 Constructing Roads In JGShining's Kingdom(最长上升子序列)

    题意:贫穷和富有的城市都按顺序1-n排列,需要在中间建造尽可能多的道路,最多可以建造多少条? 解:如果条件这样给出,贫穷的城市按顺序排列,并且按顺序给出每个贫穷城市需要的资源,那么能建造的最多的道路数 ...

  8. HDU 1025 Constructing Roads In JGShining's Kingdom(DP+二分)

    点我看题目 题意 :两条平行线上分别有两种城市的生存,一条线上是贫穷城市,他们每一座城市都刚好只缺乏一种物资,而另一条线上是富有城市,他们每一座城市刚好只富有一种物资,所以要从富有城市出口到贫穷城市, ...

  9. hdu 1025 Constructing Roads In JGShining’s Kingdom 【dp+二分法】

    主题链接:pid=1025">http://acm.acmcoder.com/showproblem.php?pid=1025 题意:本求最长公共子序列.但数据太多. 转化为求最长不下 ...

随机推荐

  1. SpringBoot启动的时候出现log4j警告(配置文件找不到)

    SpringBoot启动的时候报如下的警告 在启动SpringBoot项目的时候,idea出现如下警告信息,也就是log4j 配置文件找不到的问题 log4j:WARN No appenders co ...

  2. npm git 常用命令行 记录

    1. 推出node命令行: 两次ctrl+C或者一次ctrl+D    退出终端:exit; 2.npm 常用 npm install <name>  安装包 npm install &l ...

  3. Building Applications with Force.com and VisualForce(Dev401)(十七):Data Management: Data management Tools

    ev401-018:Data Management: Data management ToolsModule Objectives1.List objects exposed in the impor ...

  4. msys2 mingw64安装

    (1)安装msys2 (2)更新\etc\pacman.d\下的源文件 mirrorlist.msys Server = http://repo.msys2.org/msys/$arch/ Serve ...

  5. 【干货】史上最全的Tensorflow学习资源汇总

    欢迎大家关注我们的网站和系列教程:http://www.tensorflownews.com/,学习更多的机器学习.深度学习的知识! 作者:AI小昕 在之前的Tensorflow系列文章中,我们教大家 ...

  6. CSS3 - 新单位vw、vh、vmin、vmax使用详解

    参考文章出自:https://www.hangge.com/blog/cache/detail_1715.html

  7. 前端学习(3)-CSS

    一 CSS CSS是Cascading Style Sheets的缩写,层叠样式表,用来控制网页数据的显示,可以使网页的显示与数据内容分离. 二 引入方式 (1)行内式:在标记的style属性中设置C ...

  8. 运行redis数据库

    启动redis服务器:redis-server /usr/local/redis-5.0.5/etc/redis.conf 关闭: redis-cli shutdown启动客户端:进入bin文件夹,输 ...

  9. Conda安装包错误-CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://conda.anaconda.org/r/win-64/repodata.json> Elapsed:

    可能是防火墙问题:conda config --set ssl_verify false 安装 openssl . 换源: cmd输入conda config --add channels r 进入C ...

  10. [tyvj2032]升降梯上<dp&spfa>

    题目背景 开启了升降梯的动力之后,探险队员们进入了升降梯运行的那条竖直的隧道,映入眼帘的是一条直通塔顶的轨道.一辆停在轨道底部的电梯.和电梯内一杆控制电梯升降的巨大手柄. 题目描述 Nescafe 之 ...