最少拦截系统

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 19172    Accepted Submission(s): 7600

Problem Description

国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能
超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.
 
Input
输入若干组数据.每组数据包括:导弹总个数(正整数),导弹依此飞来的高度(雷达给出的高度数据是不大于30000的正整数,用空格分隔)
 
Output
对应每组数据输出拦截所有导弹最少要配备多少套这种导弹拦截系统.
 
Sample Input
8 389 207 155 300 299 170 158 65
 
Sample Output
2
 
Source
 
这道题,简单,做法多样,适合用来训练多种dp结构:
比如LIS
代码:
 //#define LOCAL
#include<cstring>
#include<cstdio>
#include<vector>
#include<iostream>
using namespace std;
const int inf=0x3f3f3f3f;
int n;
vector<int>aa,ans;
int binary(int v,int len)
{
int r=len,l=,mid;
while(l<=r)
{
mid=l+(r-l)/;
if(ans[mid]<=v)
l=mid+;
else
r=mid-;
}
return l;
} int LIS()
{
int i,res=,j;
for(i=;i<=n;i++)
ans[i]=inf;
for(i=;i<=n;i++)
{
j=binary(aa[i],res);
if(res<j) res=j;
if(ans[j]>=aa[i])
ans[j]=aa[i];
}
return res;
}
int main()
{
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif
while(scanf("%d",&n)!=EOF)
{
aa.resize(n+);
ans.resize(n+);
for(int i=;i<=n;i++)
cin>>aa[i];
printf("%d\n",LIS());
}
return ;
}

hdu----(1257)最少拦截系统(dp/LIS)的更多相关文章

  1. POJ - 2533 Longest Ordered Subsequence与HDU - 1257 最少拦截系统 DP+贪心(最长上升子序列及最少序列个数)(LIS)

    Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let ...

  2. HDU 1257——最少拦截系统——————【LIS变型题】

    最少拦截系统 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  3. HDU 1257 最少拦截系统 (DP || 贪心)

    最少拦截系统 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  4. HDU 1257 最少拦截系统【LIS】

    题意:类似于套娃娃,问最少需要多少个拦截系统. 思路: 假设已经有m个导弹拦截序列 r1:x11>=x12>=x13>=...>=x1n r1:x21>=x22>= ...

  5. POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心

    参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你 ...

  6. HDU 1257 最少拦截系统 ——(LIS)

    想了一下感觉和lis有关,交了果然AC.想不到很好的证明方法,试做证明如下:lis的每一个点都是一个不上升系统中的一员,设其为a[i],那么a[i-1]<a[i]肯定是成立的(lis的性质),夹 ...

  7. HDU 1257 最少拦截系统 最长递增子序列

    HDU 1257 最少拦截系统 最长递增子序列 题意 这个题的意思是说给你\(n\)个数,让你找到他最长的并且递增的子序列\((LIS)\).这里和最长公共子序列一样\((LCS)\)一样,子序列只要 ...

  8. HDU 1257 最少拦截系统(贪心 or LIS)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)   ...

  9. HDU 1257最少拦截系统[动态规划]

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1257                                                 最 ...

  10. hdu 1257 最少拦截系统【贪心 || DP——LIS】

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257 http://acm.hust.edu.cn/vjudge/contest/view.action ...

随机推荐

  1. ProgressBar 的使用

    ProgressBar 的使用方法 转载:http://blog.csdn.net/mad1989/article/details/38042875

  2. File Checksum Integrity Verifier

    Microsoft (R) File Checksum Integrity Verifier V2.05 README file =================================== ...

  3. emacs学习

    (set-default-font "Consolas-14")      // 设置字体及其大小 M-数字 命令 C-数字 命令

  4. Python入门-多行语句

    1. Python语句中一般以新行作为为语句的结束符. 但是我们可以使用斜杠( \)将一行的语句分为多行显示. 2. 语句中包含[], {} 或 () 括号就不需要使用多行连接符. days = [' ...

  5. shiro-web整合

    1.所需要jar <!-- shiro核心包 --> <dependency> <groupId>org.apache.shiro</groupId> ...

  6. curl的简单使用

    <?php namespace Home\Controller; use Think\Controller; class IndexController extends Controller { ...

  7. 实现jQuery扩展总结

    开发自己需要的jQuery插件,看个示例说明<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"&qu ...

  8. Android activity四种基本启动模式

    standard:默认的模式,每次启动会新创建一个activity对象 singleTop:在当前任务栈中,判断栈顶是否为当前的activity,如果是,就直接使用,如果不是,就会创建新的activi ...

  9. C/C++中static关键字作用总结

    来来来,来看这篇文章: http://www.cnblogs.com/biyeymyhjob/archive/2012/07/19/2598815.html 总结一下: 1.先来介绍它的第一条也是最重 ...

  10. 关于协程的学习 & 线程栈默认10M

    先看的这篇文章:http://blog.csdn.net/qq910894904/article/details/41699541 以nginx为代表的事件驱动的异步server正在横扫天下,那么事件 ...