导弹防御系统java_导弹防御问题 动态规划 java

Description

某国为了防御敌国的导弹袭击,开发出一种导弹拦截系统。但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度。某天,雷达捕捉到敌国的导弹来袭,并观测到导弹依次飞来的高度,请计算这套系统最多能拦截多少导弹。拦截来袭导弹时,必须按来袭导弹袭击的时间顺序,不允许先拦截后面的导弹,再拦截前面的导弹。

Input

输入有两行,

第一行,输入雷达捕捉到的敌国导弹的数量k(k<=25),

第二行,输入k个正整数,表示k枚导弹的高度,按来袭导弹的袭击时间顺序给出,以空格分隔。

Output

输出只有一行,包含一个整数,表示最多能拦截多少枚导弹。

Sample Input

8300 207 155 300 299 170 158 65

package com.test;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class DPMissile {

/**

* @param args

* @throws IOException

*/

public static void main(String[] args) throws IOException {

// TODO Auto-generated method stub

InputStreamReader in=new InputStreamReader(System.in);

BufferedReader br=new BufferedReader(in);

String s1=br.readLine();

String s2=br.readLine();

String []a=s2.split(” “);

String []Height=new String [a.length];

String []count=new String [a.length];

int totalCount=0;

for(int i=a.length-1;i>=0;i–)

{

if(i==a.length-1)

{

Height[a.length-1]=a[a.length-1];

count[a.length-1]=String.valueOf(1);

totalCount=1;

}

else

{

//System.out.println(Height[i+1]);

if(Integer.valueOf(a[i])>=Integer.valueOf(Height[i+1]))

{

count[i]=Integer.valueOf(count[i+1])+1+””;

Height[i]=a[i];

totalCount++;

}

else

{

Height[i]=Height[i+1];

count[i]=count[i+1];

}

}

}

System.out.println(totalCount);

}

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值