hdu 1025 Constructing Roads In JGShining's Kingdom(最长上升子序列)
题意:贫穷和富有的城市都按顺序1-n排列,需要在中间建造尽可能多的道路,最多可以建造多少条?
解:如果条件这样给出,贫穷的城市按顺序排列,并且按顺序给出每个贫穷城市需要的资源,那么能建造的最多的道路数就是这个顺序中的最长上升子序列的长度。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map> using namespace std;
typedef long long ll; const int maxn=1e5+; ll n,a[maxn];
ll dp[maxn]; ll lower_bound(ll *a,int x,int y,ll v){
int m;
while(x<y){
m=x+(y-x)/;
if(a[m]>=v)y=m;
else x=m+;
}
return x;
} ll q[maxn],r[maxn]; int main(){
int o=;
while(scanf("%lld",&n)!=EOF){
for(int i=;i<n;i++){
scanf("%lld%lld",&q[i],&r[i]);
}
for(int i=;i<n;i++){
a[q[i]-]=r[i]-;
}
int m=;
for(int i=;i<n;i++){
if(m==||dp[m-]<a[i]){
dp[m++]=a[i];
}else{
ll j=lower_bound(dp,,m,a[i]);
dp[j]=a[i];
}
/*验证正确性
for(int j=0;j<m;j++){
printf("%lld ",dp[j]);
}printf("\n");
*/
}
printf("Case %d:\n",o++);
printf("My king, at most %d road",m);
if(m>)printf("s");
printf(" can be built.\n\n"); }
return ;
}
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 ...
- 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 ...
- [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(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求最长非递减子序列]
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(DP+二分)
点我看题目 题意 :两条平行线上分别有两种城市的生存,一条线上是贫穷城市,他们每一座城市都刚好只缺乏一种物资,而另一条线上是富有城市,他们每一座城市刚好只富有一种物资,所以要从富有城市出口到贫穷城市, ...
- hdu 1025 Constructing Roads In JGShining’s Kingdom 【dp+二分法】
主题链接:pid=1025">http://acm.acmcoder.com/showproblem.php?pid=1025 题意:本求最长公共子序列.但数据太多. 转化为求最长不下 ...
- hdu 1025 Constructing Roads In JGShining's Kingdom
本题明白题意以后,就可以看出是让求最长上升子序列,但是不知道最长上升子序列的算法,用了很多YY的方法去做,最后还是超时, 因为普通算法时间复杂度为O(n*2),去搜了题解,学习了一下,感觉不错,拿出来 ...
- 最长上升子序列 HDU 1025 Constructing Roads In JGShining's Kingdom
最长上升子序列o(nlongn)写法 dp[]=a[]; ; ;i<=n;i++){ if(a[i]>dp[len]) dp[++len]=a[i]; ,dp++len,a[i])=a[i ...
随机推荐
- 如何在git搭建自己博客
1.安装Node.js和配置好Node.js环境,打开cmd命令行输入:node v.2.安装Git和配置好Git环境,打开cmd命令行输入:git --version.3.Github账户注册和新建 ...
- 通过 Serverless 加速 Blazor WebAssembly
Blazor ❤ Serverless 我正在开发 Ant Design 的 Blazor 版本,预览页面部署在 Github Pages 上,但是加载速度很不理想,往往需要 1 分钟多钟才完成. 项 ...
- Mysql 删除从数据库的relay logs最佳方式、最安全方式
情景 MySQL数据库主从复制在默认情况下从库的relay logs会在SQL线程执行完毕后被自动删除.但是:在relay_log_purge = 0和MHA集群下,不会被自动删除,需要手动删除.如何 ...
- JS将扁平化的数据处理成Tree结构
let jsonData= [ { id:1, parentId:0, name:"一级菜单A" }, { id:2, parentId:0, name:"一级菜单B& ...
- if-else连用时的陷阱
近日,在实现<The C Programing Language>上的一个练习题时,写出了下面一段代码 ; i<=right; i++) { ) ) swap(v, i, ++la ...
- 手把手教你快速使用数据可视化BI软件创建互联网用户数据分析大屏
灯果数据可视化BI软件是新一代人工智能数据可视化大屏软件,内置丰富的大屏模板,可视化编辑操作,无需任何经验就可以创建属于你自己的大屏.大家可以在他们的官网下载软件. 本文以互联网用户数据分析大屏为 ...
- springboot 后台框架平台 mybatis 集成代码生成器 shiro 权限 websocket
1.代码生成器: [正反双向](单表.主表.明细表.树形表,快速开发利器)freemaker模版技术 ,0个代码不用写,生成完整的一个模块,带页面.建表sql脚本.处理类.service等完整模块2. ...
- Binder基本使用
Android开发中,Binder是一种跨进程通信方式,而使用AIDL可以实现Binder的工作. 如何使用它是了解它的第一步,本文章主要记录使用Binder的一些步骤.(代码思路参考<Andr ...
- 范式通俗理解:1NF、2NF、3NF和BNCF
https://blog.csdn.net/wyh7280/article/details/83350722 范式通俗理解:1NF.2NF.3NF和BNCF原创hongiii 最后发布于2018-10 ...
- Linux kernel简介
内核体系设计分:单内核,微内核 windows是微内核设计. Linux是单内核设计,但充分借鉴了为微内核体系的优点,为内核引入了模块化机制. 内核的组成部分 kernel:内核核心,一般为bz压缩的 ...