最长上升子序列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. [set]Codeforces 830B-Cards Sorting

    Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. WeChat 搭建过程

    [被动回复消息] 1.创建项目(基于MyEclipse + Tomcat 7 编写):wechat 2.导入jar包(用于解析xml):dom4j-1.6.1.jar,xstream-1.3.jar ...

  3. Hive常用的10个系统函数及作用

    聚合函数 函数处理的数据粒度为多条记录. sum()—求和 count()—求数据量 avg()—求平均直 distinct—求不同值数 min—求最小值 max—求最人值 分析函数 Analytic ...

  4. 四、用户交互(输入input,格式化输出)与运算符

    1.接收用户的输入 在Python3:input会将用户输入的所有内容都存成字符串类型 列: username = input("请输入您的账号:") # "egon&q ...

  5. ​GAN的五大有趣应用

    引言 你能看出这张照片中面部的共同点吗? 这些人都不是真实存在的!这些面部图像都是由GAN技术生成的. "GAN"这个词是由Ian Goodfellow在2014年提出的,但相关概 ...

  6. FileReader 和Blob File文件对象(附formData初始化方法);

    一.FileReader为读取文件对象 . api  地址   相关demo 现在只讨论  readAsArrayBuffer,readAsBinaryString,readAsDataURL,rea ...

  7. RocketMQ调研

    一.发展历程 早期淘宝内部有两套消息中间件系统:Notify和Napoli. 先有的Notify(至今12历史),后来因有序场景需求,且恰好当时Kafka开源(2011年),所以参照Kafka的设计理 ...

  8. FarmCraft --(树形DP)

    题目描述 In a village called Byteville, there are houses connected with N-1 roads. For each pair of hous ...

  9. 老技术新谈,Java应用监控利器JMX(3)

    各位坐稳扶好,我们要开车了.不过在开车之前,我们还是例行回顾一下上期分享的要点. 上期我们深入的聊了聊 JMX,把 JMX 的架构了解了七七八八,最后通过代码实战,解决系列疑问,实现远程动态修改应用参 ...

  10. css3之 景深

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...