hdu 1257 一共要多少套拦截系统 (LIS)
给出导弹的高度 拦截的导弹会比上一次低 至少要几套拦截系统才能防御所有导弹
求一套系统能防御的最大导弹数: 反向LIS
求一共要多少套:正向LIS
Sample Input
8 389 207 155 300 299 170 158 65
Sample Output
2
# include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <cmath>
# define LL long long
using namespace std ; int a[] ;
int f[] ;
//int dp[100010] ;
int n ; int bsearch(int size, const int &a) {
int l=, r=size-;
while( l <= r ){
int mid = (l+r)/;
if( a > f[mid-] && a <= f[mid] ) return mid;// >&&<= 换为: >= && <
else if( a < f[mid] ) r = mid-;
else l = mid+;
}
} int LIS()
{
int i, j, size = ;
f[] = a[];
//dp[0] = 1;
for( i=; i < n; ++i )
{
if( a[i] <= f[] ) j = ; // <= 换为: <
else if( a[i] > f[size-] ) j = size++;// > 换为: >=
else j = bsearch(size, a[i]);
f[j] = a[i];
//dp[i] = j+1;
}
return size;
} int main ()
{
//freopen("in.txt","r",stdin) ;
while(scanf("%d" , &n) !=EOF)
{
int i ;
for (i = ; i < n ; i++)
scanf("%d" , &a[i]) ;
printf("%d\n" , LIS()) ; // 求最大递增/上升子序列(如果为最大非降子序列,只需把上面的注释部分给与替换)
} return ;
}
hdu 1257 一共要多少套拦截系统 (LIS)的更多相关文章
- HDU1257:最少拦截系统(LIS)
Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高 ...
- HDU 1257 最少拦截系统(Dilworth定理+LIS)
最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- HDU 1257 最少拦截系统 (DP || 贪心)
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- (hdu)1257 最少拦截系统
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1257 Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦 ...
- (最长不降子序列)最少拦截系统 -- hdu -- 1257
http://acm.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) Memo ...
- HDU 1257 最少拦截系统(贪心 or LIS)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others) ...
- hdu dp 1257 最小拦截系统
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- hdu 1257 最少拦截系统【贪心 || DP——LIS】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 1257——最少拦截系统——————【LIS变型题】
最少拦截系统 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
随机推荐
- JAVA迭代器学习--在JAVA中实现线性表的迭代器
1,迭代器是能够对数据结构如集合(ADT的实现)进行遍历的对象.在遍历过程中,可以查看.修改.添加以及删除元素,这是它与一般的采用循环来遍历集合中的元素不同的地方.因为,通常用循环进行的遍历操作一般是 ...
- static, const
static 静态的,类的静态成员函数,静态成员变量是和类相关的,但不和具体对象相关.即使没有具体对象,也能调用类的静态成员函数和成员变量.一般类的静态函数就是一个全局函数,只是作用域在包含它的文件中 ...
- js scroll函数
$(function () { $(".sticky").hide(); var top = $(window).scrollTop(); if (top >= 100) { ...
- 第16月第12天 CABasicAnimation 旋转加速
1. ; double duration = 10.0f; ; i<count; i++) { //旋转动画 CABasicAnimation *anima3 = [CABasicAnimati ...
- 启动apache 提示Starting httpd: AH00558
Starting httpd: AH00558: httpd: Could not reliably determine the server's fully qualified domain nam ...
- 修改weblogic的端口
两种方法可以修改,第一种方法是后台管理界面修改,第二种是配置文件修改,下面分别介绍: 1.后台修改 (1)进入weblogic登陆界面:(默认端口是7001) (2)登陆之后点击服务器----然后管理 ...
- spring整合ehcache2.5.2缓存异常-- net.sf.ehcache.CacheException
报错如下: The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcach ...
- 【网络编程4】网络编程基础-ARP响应(ARP欺骗之中间人攻击)
arp欺骗->arp响应 ARP 缓存中毒(ARP欺骗) arp传送原理在于主机发送信息时将包含目标IP地址的ARP请求广播到网络上的所有主机,并接收返回消息,以此确定目标的物理地址:收到返回消 ...
- MySQL各个版本区别及问题总结
参考:http://www.admin10000.com/document/62.html 一.简介 MySQL 的官网下载地址:http://www.mysql.com/downloads/ 在这个 ...
- React-Native 之 网络请求 fetch
前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会有所 ...