蓝桥杯-算法训练 拦截导弹

问题描述

某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统。但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度。某天,雷达捕捉到敌国的导弹来袭。由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹。

输入导弹依次飞来的高度(雷达给出的高度数据是不大于30000的正整数),计算这套系统最多能拦截多少导弹,如果要拦截所有导弹最少要配备多少套这种导弹拦截系统。

输入格式

一行,为导弹依次飞来的高度

输出格式

两行,分别是最多能拦截的导弹数与要拦截所有导弹最少要配备的系统数

样例输入

389 207 155 300 299 170 158 65

样例输出

6
2

锦囊1

贪心和动态规划算法。

锦囊2

求一套系统拦截的导弹最大值为最长不下降子序列问题,用动态规划。 求最少多少套系统需要使用贪心法,每枚后面的炮弹使用能拦截它的最低的系统。

参考代码

此处为隐藏的内容!
发表评论并刷新,才能查看
俊霖

发表评论

您必须

目前评论:16   其中:访客  15   博主  1


    Warning: A non-numeric value encountered in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/comment-template.php on line 20
  1. ttsuperman 3

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  2. 吴记麻辣油 1

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  3. 云淡风轻 1

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  4. Deepsilent 1

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  5. zhaozhenwei 1

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  6. hhuuj 1

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  7. Matrix42 1

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  8. ymx200181 5

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  9. Lions 3

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  10. 微笑、掩盖忧伤 2

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  11. QB20D4A99E3BCB0609A7A245A026F7AAA 1

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  12. xiawengggasd 1

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  13. 喑夜背影 0

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  14. 0

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566
  15. 十二 2

    Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /www/wwwroot/jurieo.com/wp-content/themes/begin2.0/inc/function/default.php on line 566