900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 导弹防御系统java_导弹防御问题 动态规划 java

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

时间:2022-06-22 21:47:57

相关推荐

导弹防御系统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);

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。