拦截导弹
来源:互联网 发布:淘宝越刷排名越靠后 编辑:程序博客网 时间:2024/05/21 09:18
描述
某国为了防御敌国的导弹袭击,开发出一种导弹拦截系统。但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度。某天,雷达捕捉到敌国的导弹来袭,并观测到导弹依次飞来的高度,请计算这套系统最多能拦截多少导弹。拦截来袭导弹时,必须按来袭导弹袭击的时间顺序,不允许先拦截后面的导弹,再拦截前面的导弹。
输入
输入有两行,
第一行,输入雷达捕捉到的敌国导弹的数量k(k<=25),
第二行,输入k个正整数,表示k枚导弹的高度,按来袭导弹的袭击时间顺序给出,以空格分隔。
输出
输出只有一行,包含一个整数,表示最多能拦截多少枚导弹。
样例输入
8
300 207 155 300 299 170 158 65
样例输出
6
解题思路
此题与最长递增序列的题类似,要找最长递减序列的长度,不用多说思路就是动态规划。(PS:如果真的要见思路就看最长递增序列题的思路吧。。链接为:http://blog.csdn.net/qq_30091945/article/details/58586046)
AC代码
#include <iostream>using namespace std;int Max(int a , int b){ return (a > b)?a:b; } int main(){ int N; cin>>N; int Height[N+1]; int cnt[N+1]; int max = 1; for ( int i = 1 ; i <= N ; i++){ cin>>Height[i]; cnt[i] = 1; } for ( int i = 2 ; i <= N ; i++){ for ( int j = 1 ; j < i ; j++){ if(Height[i] <= Height[j]){ cnt[i] = Max(cnt[i],cnt[j]+1); } } if ( max < cnt[i]){ max = cnt[i]; } } cout<<max; return 0; }
0 0
- 拦截导弹
- 拦截导弹
- 拦截导弹
- 拦截导弹
- 导弹拦截
- 导弹拦截
- 拦截导弹
- 拦截导弹
- 拦截导弹
- 拦截导弹
- 拦截导弹
- 拦截导弹
- 拦截导弹
- 拦截导弹
- 拦截导弹
- 拦截导弹
- 拦截导弹
- 拦截导弹
- 前端和后端是如何交互的
- Win10 64bit安装VC6+VC6助手
- 布局
- 15. 3Sum,16. 3Sum Closest,18. 4Sum(最后一个方法重要)重要
- poj 2549 Sumsets
- 拦截导弹
- SAS 关联规则
- CF
- form表单中的lable标签
- Internet Explorer(CVE-2012-1889)暴雷漏洞分析报告【WinXP&IE8版】
- 解决Cannot change version of project facet Dynamic web module to 3.0
- Linux
- 排序算法优劣
- Hibernate使用ServiceRegistryBuilder出错