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 ...
随机推荐
- Study 6 —— 字体和段落属性
字体风格{font-style:normal | italic | oblique | inherit字体复合属性{font:font-style font-variant font-weight f ...
- HDU - 5419 Victor and Toys(组合计数)
http://acm.hdu.edu.cn/showproblem.php?pid=5419 题意 n个物品,标号1-n,物品i有权值wi.现在有m个区间[l,r],从中任意选三个区间i,j,k,求物 ...
- Ant基础知识2
Ant: 1.在windows上搭建Ant环境,成功后查看版本号 答案: (1)安装jdk,配置环境变量 (2)安装ant,配置环境变量,添加ANT_HOME,在path中加入%ANT_HOME%\b ...
- centos7 memcached+magent+keepalived集群
111,222均部署keepalived,magent,memcached keepalived 111为主机,222为备机 其中,111上magent以本地memcache为主,222为备用 222 ...
- java程序在windows后台执行的办法
1.新建run.txt文件 2.在文件中输入一下内容: @echo off start javaw -jar xx.jar exit 3.保存,修改文件名为run.bat4.双击即可 5.删除wind ...
- linux4.10.8 内核移植(四)---字符设备驱动_led驱动程序
一.字符设备驱动程序介绍 app里面用 open.read.write等等函数出来操作底层硬件.驱动程序中也有对应的xxx_open等函数.怎么找到驱动程序中的函数依赖于驱动程序框架. 二.搭建驱动程 ...
- luogu P4360 [CEOI2004]锯木厂选址
斜率优化dp板子题[迫真] 这里从下往上标记\(1-n\)号点 记\(a_i\)表示前缀\(i\)里面树木的总重量,\(l_i\)表示\(i\)到最下面的距离,\(s_i\)表示\(1\)到\(i-1 ...
- 第18月第16天 statusBar
1. 我们都知道要改状态栏statusBar的颜色很简单,只要如下一行代码就可以, [[UIApplicationsharedApplication]setStatusBarStyle:UIStatu ...
- 交换机console口连接
http://www.webkaka.com/info/archives/knowledge/2010/08/30452/
- 深入理解 RecyclerView 系列之:ItemDecoration
https://blog.piasy.com/2016/03/26/Insight-Android-RecyclerView-ItemDecoration/?utm_source=tuicool&am ...