HDU 1025 Constructing Roads In JGShining‘s Kingdom
Posted jpphy0
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 1025 Constructing Roads In JGShining‘s Kingdom相关的知识,希望对你有一定的参考价值。
Constructing Roads In JGShining’s Kingdom
http://acm.hdu.edu.cn/showproblem.php?pid=1025
分析
- 最长上升子序列
- O(nlogn)
代码
// hdu 1025 Constructing Roads In JGShining's Kingdom
#include <bits/stdc++.h>
using namespace std;
#define MXN 500010
#define fmt "Case %d:\\nMy king, at most %d road%s can be built.\\n\\n"
int a[MXN], dp[MXN], n, len;
int main() {
int p, r, t = 0;
while (scanf("%d", &n) == 1) {
for(int i = 1; i <= n; ++i){
scanf("%d %d", &p, &r);
a[p] = r;
}
len = 1, dp[1] = a[1];
for(int i = 2; i <= n; ++i){
if(dp[len] < a[i]) dp[++len] = a[i];
else *lower_bound(dp+1, dp+len+1, a[i]) = a[i];
}
printf(fmt, ++t, len, len==1?"":"s");
}
return 0;
}
以上是关于HDU 1025 Constructing Roads In JGShining‘s Kingdom的主要内容,如果未能解决你的问题,请参考以下文章
HDU 1025:Constructing Roads In JGShining's Kingdom(LIS+二分优化)
HDU 1025 Constructing Roads In JGShining's Kingdom
hdu-1025 Constructing Roads In JGShining's Kingdom(二分查找)
hdu1025 Constructing Roads In JGShining's Kingdom(二分+dp)
Constructing Roads In JGShining's Kingdom(HDU 1025 LIS nlogn方法)