最长上升子序列 HDU 1025 Constructing Roads In JGShining's Kingdom
最长上升子序列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的更多相关文章
- HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP)
HDOJ(HDU).1025 Constructing Roads In JGShining's Kingdom (DP) 点我挑战题目 题目分析 题目大意就是给出两两配对的poor city和ric ...
- [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 ...
- 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 ...
- 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 ...
- 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 ...
- HDU 1025 Constructing Roads In JGShining's Kingdom(求最长上升子序列nlogn算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025 解题报告:先把输入按照r从小到大的顺序排个序,然后就转化成了求p的最长上升子序列问题了,当然按p ...
- hdu 1025 Constructing Roads In JGShining's Kingdom(最长上升子序列)
题意:贫穷和富有的城市都按顺序1-n排列,需要在中间建造尽可能多的道路,最多可以建造多少条? 解:如果条件这样给出,贫穷的城市按顺序排列,并且按顺序给出每个贫穷城市需要的资源,那么能建造的最多的道路数 ...
- HDU 1025 Constructing Roads In JGShining's Kingdom(DP+二分)
点我看题目 题意 :两条平行线上分别有两种城市的生存,一条线上是贫穷城市,他们每一座城市都刚好只缺乏一种物资,而另一条线上是富有城市,他们每一座城市刚好只富有一种物资,所以要从富有城市出口到贫穷城市, ...
- hdu 1025 Constructing Roads In JGShining’s Kingdom 【dp+二分法】
主题链接:pid=1025">http://acm.acmcoder.com/showproblem.php?pid=1025 题意:本求最长公共子序列.但数据太多. 转化为求最长不下 ...
随机推荐
- vue 2
目录 复习 今日 指令 条件指令 循环指令 评论案例 解决插值表达式符号冲突 总结 组件 局部组件 全局组件 组件间的交互:父传子 组件间的交互:子传父 复习 """ 1 ...
- IdentityServer4源码解析_4_令牌发放接口
目录 identityserver4源码解析_1_项目结构 identityserver4源码解析_2_元数据接口 identityserver4源码解析_3_认证接口 identityserver4 ...
- nopcommerce4.0 安装步骤
前言:近期因工作要求接触nopcommerce,最新版本为4.0,以下所有安装都是基于此版本.接下来我可能会写一系列,为了让自己更好的掌握,也希望能帮助到大家 好记性不如烂笔头,新手也可以避免走我的弯 ...
- R与金钱游戏:美股与ARIMA模型预测
似乎突如其来,似乎合情合理,我们和巴菲特老先生一起亲见了一次,又一次,双一次,叒一次的美股熔断.身处历史的洪流,渺小的我们会不禁发问:那以后呢?还会有叕一次吗?于是就有了这篇记录:利用ARIMA模型来 ...
- SpringBoot安装与配置
1.环境准备 1.1.Maven安装配置 Maven项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的项目管理工具软件. 下载Maven可执行文件 cd /usr/local ...
- Web Scraper 性能测试 (-_-)
刚在研究 Python 爬虫的时候,看到了个小白工具,叫 Web Scraper,于是来测试下好不好用. Web Scraper 是什么? 它是一个谷歌浏览器的插件, 用于批量抓取网页信息, 主要特点 ...
- 模块 jieba结巴分词库 中文分词
jieba结巴分词库 jieba(结巴)是一个强大的分词库,完美支持中文分词,本文对其基本用法做一个简要总结. 安装jieba pip install jieba 简单用法 结巴分词分为三种模式:精确 ...
- 无法像程序语言那样写SQL查询语句,提示“数据库中已存在名为 '#temp1' 的对象。”
if exists( select exp_count from tbl_expend where exp_valid ),exp_date,) ),) ) begin select exp_coun ...
- Vertica的这些事(四)——-vertica加密数据
通过创建 Secure Access Policies可以对vertica中的某一列数据进行加密: CREATE ACCESS POLICY ON [schema][tablename] FOR CO ...
- 悟懂MapReduce,不纠结!
在<谷歌 MapReduce 初探>中,我们通过统计词频的 WordCount 经典案例,对 Google 推出的 MapReduce 编程模型有了一个认识,但是那种认识,还只是停留在知道 ...