题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1257

最少拦截系统

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

Problem Description
某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统.
 
Input
输入若干组数据.每组数据包括:导弹总个数(正整数),导弹依此飞来的高度(雷达给出的高度数据是不大于30000的正整数,用空格分隔)
 
Output
对应每组数据输出拦截所有导弹最少要配备多少套这种导弹拦截系统.
 
Sample Input
8 389 207 155 300 299 170 158 65
 
Sample Output
2
 
Source
分析:
两种解决方式,贪心和LIS
贪心解法分析:
样例一:
389 207 155 300 299 170 158 65
解法:
第一套拦截系统:389 207 155 65
第二套拦截系统:300 299 170 158 
样例二:
5 3 6 7 2 10 9 11 8
第一套拦截系统:5  3  2
第二套拦截系统:6
第三套拦截系统:7
第四套拦截系统:10  9  8
第五套拦截系统:11
代码如下:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n))
{
int a[n];
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
int dp[n];
memset(dp,-,sizeof(dp));
dp[]=a[];
int k=;
for(int i=;i<n;i++)
{
if(a[i]>=dp[k])
{
dp[++k]=a[i];
}else
{
for(int j=;j<=k;j++)
{
if(dp[j]>a[i])
{
dp[j]=a[i];
break;
}
}
}
}
int s=;
for(int i=;i<n;i++)
{
if(dp[i]!=-)
{
s++;
}
}
printf("%d\n",s);
}
return ;
}

二,LIS解法:

一个序列中,最长上升子序列的长度就是不下降子序列的个数。

这句话很重要,理解了这句话题目就ok

看了别人的博客然后理解了。。。。

代码如下:

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n))
{
int a[n];
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
int dp[n];
memset(dp,,sizeof(dp));
dp[]=;
for(int i=;i<n;i++)
{
int t=;
for(int j=;j<i;j++)
{
if(a[j]<a[i])
{
if(t<dp[j])
{
t=dp[j];
}
}
}
dp[i]=t+;
}
int t=;
for(int i=;i<n;i++)
{
if(t<dp[i])
{
t=dp[i];
}
}
printf("%d\n",t);
}
return ;
}

HDU 1257 最少拦截系统(贪心 or LIS)的更多相关文章

  1. hdu 1257 最少拦截系统(贪心)

    解题思路:[要充分理解题意,不可断章取义] 贪心:每个防御系统要发挥其最大性能, 举例: Input : 9 389 207 155 300 299 170 155 158 65 Output: 2 ...

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

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

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

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

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

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

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

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

  6. HDU 1257 最少拦截系统(Dilworth定理+LIS)

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

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

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

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

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

  9. hdu 1257 最少拦截系统(动态规划 / 贪心)

    最少拦截系统 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

随机推荐

  1. [清华集训]Rmq Problem / mex

    题目链接 我们离线处理这些询问 在右端点所在的位置用vector来push_back询问 维护每个数值最后出现的位置p[x] 从左往右扫,边走边回答询问 对于每个询问我们回答第一个p[x]<l的 ...

  2. mysqli 查询

    $mysqli = new mysqli('localhost', 'user', 'pwd', 'dbname'); $query = "select goods_id,goods_nam ...

  3. arcgis 加载高德地图 es6的方式

    目前很多arcgis 加载高德地图是dojo的方式 外部引入文件,现在改成这种方式 /** * Created by Administrator on 2018/5/14 0014. */ impor ...

  4. [翻译] WPAttributedMarkup

    WPAttributedMarkup https://github.com/nigelgrange/WPAttributedMarkup WPAttributedMarkup is a simple ...

  5. 使用开源库 MagicalRecord 操作 CoreData

    MagicalRecord  https://github.com/magicalpanda/MagicalRecord 注意:  MagicalRecord 在 ARC 下运作,Core Data ...

  6. Spring @Autowired注解在非Controller/Service中注入为null

    参考:https://blog.csdn.net/qq_35056292/article/details/78430777 问题出现: 在一个非controller/service类中,我需要注入Co ...

  7. C盘下出现msdia80.dll文件

    删除方法 https://jingyan.baidu.com/article/63acb44acef55661fdc17e56.html 或者 https://www.cnblogs.com/ggll ...

  8. Sharepoint 2013 - 直接显示Doclib中的html page

    缺省的HTML不能直接显示,会被要求存盘.以下操作可以修改 Go to Central Administration Select Manage web applications Select the ...

  9. django 错误之 OSError: mysql_config not found

    pip 导入包时出现如下错误 Complete output from command python setup.py egg_info: /bin/: mysql_config: not found ...

  10. RTCM32编解码中的一些概念及相关文献阅读

    1. IODC和 IODE ——  导航电文相关.iode/iodc是在GPS系统的ICD2中定义的参数,iode指星历数据事件,iodc指星钟数据事件. IOD 是 issue of data ,数 ...