本题明白题意以后,就可以看出是让求最长上升子序列,但是不知道最长上升子序列的算法,用了很多YY的方法去做,最后还是超时,

因为普通算法时间复杂度为O(n*2),去搜了题解,学习了一下,感觉不错,拿出来分享一下。

 #include <stdio.h>
#include <string.h> #define N 500005
int map[N], dp[N]; int main ()
{
int x, y, n, i, j = ; while (scanf ("%d", &n) != EOF)
{
for (i=; i<n; i++)
{
scanf ("%d %d", &x, &y);
map[x] = y;
} memset (dp, , sizeof(dp)); dp[] = map[]; int low, up, mid, len = ;
for (i=; i<=n; i++)
{
low = ;
up = len; while (low <= up)
{
mid = (low + up) / ;
if (dp[mid] > map[i])
up = mid - ;
else
low = mid + ;
} dp[low] = map[i];
if (low > len)
len ++;
}
if (len == )
printf ("Case %d:\nMy king, at most 1 road can be built.\n\n", ++j);
else
printf ("Case %d:\nMy king, at most %d roads can be built.\n\n", ++j, len);
} return ;
}

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. 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 ...

  3. [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 ...

  4. 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 ...

  5. 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 ...

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

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

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

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

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

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

  9. 最长上升子序列 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 ...

随机推荐

  1. js的基础(平民理解的执行上下文/调用堆栈/内存栈/值类型/引用类型)

    与以前的切图比较,现在的前端开发对js的要求似乎越来越高,在开发中,我们不仅仅是要知道如何运用现有的框架(react/vue/ng), 而且我们对一些基础的知识的依赖越来越大. 现在我们就用平民的方法 ...

  2. centos 安装python2.7

    安装pip sudo yum -y install epel-release sudo yum -y install python-pip 下载解压Python-2.7.3 #wget http:// ...

  3. Atitit.软件仪表盘(7)--温度监測子系统--电脑重要部件温度与监控and警报

    Atitit.软件仪表盘(7)--温度监測子系统--电脑重要部件温度与监控and警报 Cpu温度.风扇转速 主板温度 显卡温度 硬盘温度 电池温度 鲁大师  硬盘温度 Cpu温度  core temp ...

  4. 【Mongodb教程 第十七课 】MongoDB常用命令 数据库命令 集合操作命令

    (1)数据库命令 a)添加用户 db.addUser(‘name’,’pwd’) b)删除用户 db.removeUser(‘name’) c)用户验证 db.auth(‘name’,’pwd’) d ...

  5. Android之——AIDL深入

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/47071927 在上一篇博文<Android之--AIDL小结>中,我们 ...

  6. mt7620 uboot

    我本机装的是64位Ubuntu, SDK 里提供的 buildroot-gcc342 是32位的,无法直接运行,需要先安装 gcc-multilib. sudo apt-get install gcc ...

  7. Matplotlib绘图基础

    import matplotlib.pyplot as plt import numpy as np #绘图流程 x=np.linspace(-1,1,100) y=x**2 plt.plot(x,y ...

  8. linux 【目录】

    [第一篇]linux[目录] [第五篇]特殊权限及定时任务 [第六篇]用户和用户管理及定时任务复习

  9. 像感冒一样的contains error

    转自 http://blog.csdn.net/zhufuing/article/details/8135270          Android开发中的问题总是多种多样,今天我来总结一个浪费了我一个 ...

  10. HttpsURLConnection 安全传输(HTTPS--Secure Hypertext Transfer Protocol-安全超文本传输协议)

    HttpsURLConnection 扩展 HttpURLConnection,支持各种特定于 https 功能.此类使用 HostnameVerifier 和 SSLSocketFactory.为这 ...