当前位置:网站首页>动态规划问题05_导弹拦截
动态规划问题05_导弹拦截
2022-07-25 10:35:00 【努力的clz】
- 题目描述:
某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统。
但是这种导弹拦截系统有一个缺陷:虽然它能拦截任意高度的导弹,但是每拦截一发导弹,其拦截能力就下降到只能拦截上一次拦截的导弹高度。
某天,雷达捕捉到敌国的导弹来袭,导弹依次飞来,该拦截系统最多能拦截多少导弹呢?- Input:
输入若干个数据:导弹依次飞来的高度(雷达给出的高度数据是不大于30000的正整数,用空格分隔)。- Output:
1、输出这套系统最多能拦截多少导弹。
2、输出拦截所有导弹需要的拦截系统数目
案例输入输出:
- Input:
3890 2070 1550 3000 2990 1700 1580 650- Output:
62
#include<iostream>
#include<cstring>
using namespace std;
const int MAX = 1025;
int a[MAX],b[MAX],c[MAX];
int i,maxTp;
int n,m,x;
int main()
{
memset(a,0,sizeof(a)); // 记录导弹高度
memset(b,0,sizeof(b)); // 记录最大不下降序列长度
memset(c,0,sizeof(c));
i = 1;
m = 0; // 最多一套系统拦截的导弹数
n = 0; // 需要的拦截系统数
while(cin>>a[i]){
// 输入数据
maxTp = 0;
for(int j=1; j<=i-1; j++){
// 第i枚导弹前的导弹 与 i导弹 对比
if((a[j] >= a[i]) && (b[j]>maxTp) )
maxTp = b[j];
}
// 选择最长的序列 连接
b[i] = maxTp + 1; // 加上 第i枚导弹
if(b[i]>m)
m = b[i]; // 最大拦截数
// 至此第一个问题完成
x = 0; // 在循环中,x=0,而n可能会改变
for(int j=1; j<=n; j++){
if(c[j]>=a[i])
if(x==0)
x = j;
else
if(c[x] > c[j])
x = j;
}
if(x==0){
// 默认至少有一套拦截系统
n++;
x = n;
}
c[x] = a[i];
i++; // 准备下一枚导弹
}
cout<<m<<endl<<n<<endl;
return 0;
}
边栏推荐
- 新能源销冠宏光MINIEV,有着怎样的产品力?
- SQL注入 Less17(报错注入+子查询)
- 城市雕塑典型作品信息管理系统(图片分享系统SSM)
- 玩游戏想记录一下自己超神的瞬间?那么就来看一下如何使用Unity截图吧
- 【高并发】通过源码深度分析线程池中Worker线程的执行流程
- Game backpack system, "inventory Pro plug-in", research and learning ----- mom doesn't have to worry that I won't make a backpack anymore (unity3d)
- SQL语言(五)
- Shell 脚本参数传递时有 \r 换行符问题
- [recursion] 938. Range and of binary search tree
- [dynamic planning] 70. Climbing stairs
猜你喜欢

leetcode 剑指 Offer 27. 二叉树的镜像
信息熵的定义

Nowcodertop1-6 - continuous updating

BGP federal experiment

机智云物联网平台 STM32 ESP8266-01S 简单无线控灯

城市雕塑典型作品信息管理系统(图片分享系统SSM)

leetcode 剑指 Offer 28. 对称的二叉树

Esp8266 uses drv8833 drive board to drive N20 motor

Review recitation finishing version
Learn NLP with Transformer (Chapter 3)
随机推荐
Learn PHP -- phpstudy tips mysqld Exe: Error While Setting Value ‘NO_ ENGINE_ Solution of substitution error
城市雕塑典型作品信息管理系统(图片分享系统SSM)
There is a newline problem when passing shell script parameters \r
My colleague looked at my code and exclaimed: how can I use a singleton in unity
JS 将伪数组转换成数组
Redis 入门
Shell fourth day homework
Signal integrity (SI) power integrity (PI) learning notes (XXXIV) 100 rules of thumb for estimating signal integrity effects
Mlx90640 infrared thermal imager temperature measurement module development notes (V)
Shell 脚本参数传递时有 \r 换行符问题
Compressed list ziplist of redis
Learn NLP with Transformer (Chapter 8)
SQL注入 Less23(过滤注释符)
新能源销冠宏光MINIEV,有着怎样的产品力?
SQL language (III)
Hcip experiment (01)
PostgreSQL stepping on the pit | error: operator does not exist: UUID = character varying
用Unity不会几个插件怎么能行?Unity各类插件及教程推荐
学习路之PHP--TP5.0使用中文当别名,报“不支持的数据表达式”
B2B2C多商户系统功能丰富,极易二开!!!