博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu1025(nlon(n)最长上升子序列)
阅读量:6897 次
发布时间:2019-06-27

本文共 918 字,大约阅读时间需要 3 分钟。

 

题目链接:

 

大致思路:设置两个a,b数组,a数组存储数据,b数组存储最长不降序序列。此算法关键在于设计二分查找。

 

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#define LL long longusing namespace std;int dp[50500],a[50500];int solve(int n){ int len=1,low,high,mid; dp[1]=a[1]; for(int i=2;i<=n;i++) { low=1;high=len; while(low<=high) { mid=(low+high)/2; if(a[i]>dp[mid])low=mid+1; else high=mid-1; } dp[low]=a[i]; if(low>len)len=low; } return len;}int main(){ int n,x,y,cas=1; while(scanf("%d",&n)>0) { for(int i=1;i<=n;i++) { scanf("%d%d",&x,&y); a[x]=y; } int ans=solve(n); printf("Case %d:\n",cas++); if(ans==1) printf("My king, at most 1 road can be built.\n"); else printf("My king, at most %d roads can be built.\n",ans); printf("\n"); }}
View Code

 

转载于:https://www.cnblogs.com/lienus/p/4118491.html

你可能感兴趣的文章
简单的编辑器
查看>>
Java并发之(3):锁
查看>>
11.2JS笔记
查看>>
Qt学习之路_8(Qt中与文件目录相关操作)
查看>>
vs2010中设置qt环境的智能识别方案
查看>>
开博啦
查看>>
ZOJ 1081 Points Within( 判断点在多边形内外 )
查看>>
flex模拟微信布局
查看>>
多线程测试java接口
查看>>
with 语句
查看>>
js基础知识点总结
查看>>
HTML5的新增方法
查看>>
protobuf c++例子
查看>>
eclipse中tomcat端口被占用如何解决
查看>>
通过CImageList加载图标 报错
查看>>
纯小白入手 vue3.0 CLI - 3.2 - 路由的初级使用
查看>>
安卓开发笔记——探索EventBus(转)
查看>>
Logminer实战
查看>>
桌面虚拟化之PCoIP访问协议会话统计功能
查看>>
在.NET开发中的单元测试工具之(1)——NUnit
查看>>