Testing the CATCHER
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 13396   Accepted: 4905

Description

A military contractor for the Department of Defense has just completed a series of preliminary tests for a new defensive missile called the CATCHER which is capable of intercepting multiple incoming offensive missiles. The CATCHER is supposed to be a remarkable defensive missile. It can move forward, laterally, and downward at very fast speeds, and it can intercept an offensive missile without being damaged. But it does have one major flaw. Although it can be fired to reach any initial elevation, it has no power to move higher than the last missile that it has intercepted.

The tests which the contractor completed were computer simulations of battlefield and hostile attack conditions. Since they were only preliminary, the simulations tested only the CATCHER's vertical movement capability. In each simulation, the CATCHER was fired at a sequence of offensive missiles which were incoming at fixed time intervals. The only information available to the CATCHER for each incoming missile was its height at the point it could be intercepted and where it appeared in the sequence of missiles. Each incoming missile for a test run is represented in the sequence only once.

The result of each test is reported as the sequence of incoming missiles and the total number of those missiles that are intercepted by the CATCHER in that test.

The General Accounting Office wants to be sure that the simulation test results submitted by the military contractor are attainable, given the constraints of the CATCHER. You must write a program that takes input data representing the pattern of incoming missiles for several different tests and outputs the maximum numbers of missiles that the CATCHER can intercept for those tests. For any incoming missile in a test, the CATCHER is able to intercept it if and only if it satisfies one of these two conditions:

The incoming missile is the first missile to be intercepted in this test. 
-or- 
The missile was fired after the last missile that was intercepted and it is not higher than the last missile which was intercepted.

Input

The input data for any test consists of a sequence of one or more non-negative integers, all of which are less than or equal to 32,767, representing the heights of the incoming missiles (the test pattern). The last number in each sequence is -1, which signifies the end of data for that particular test and is not considered to represent a missile height. The end of data for the entire input is the number -1 as the first value in a test; it is not considered to be a separate test.

Output

Output for each test consists of a test number (Test #1, Test #2, etc.) and the maximum number of incoming missiles that the CATCHER could possibly intercept for the test. That maximum number appears after an identifying message. There must be at least one blank line between output for successive data sets.

Note: The number of missiles for any given test is not limited. If your solution is based on an inefficient algorithm, it may not execute in the allotted time.

Sample Input

389
207
155
300
299
170
158
65
-1
23
34
21
-1
-1

Sample Output

Test #1:
maximum possible interceptions: 6 Test #2:
maximum possible interceptions: 2
解题方法:最长下降子序列。
#include <stdio.h>
#include <iostream>
using namespace std; #define Max(a, b) a > b ? a : b int main()
{
int a[];
int temp;
int dp[];
int nCount = ;
int MAX = -;
int nCase = ;
while(scanf("%d", &temp))
{
if (temp == -)
{
break;
}
else
{
a[nCount++] = temp;
}
while(scanf("%d", &temp))
{
if (temp == -)
{
MAX = -;
for (int i = ; i < nCount; i++)
{
dp[i] = ;
}
++nCase;
for (int i = ; i < nCount; i++)
{
for (int j = ; j < i; j++)
{
if (a[i] <= a[j])
{
dp[i] = Max(dp[i], dp[j] + );
}
}
MAX = Max(MAX, dp[i]);
}
printf("Test #%d:\n maximum possible interceptions: %d\n\n", nCase, MAX);
nCount = ;
break;
}
else
{
a[nCount++] = temp;
}
}
}
return ;
}

POJ 1887 Testing the CATCHER的更多相关文章

  1. POJ 1887 Testing the CATCHER(LIS的反面 最大递减子序列)

    Language: Default Testing the CATCHER Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 1 ...

  2. Poj 1887 Testing the CATCHER(LIS)

    一.Description A military contractor for the Department of Defense has just completed a series of pre ...

  3. poj 1887 Testing the CATCHER_最长上升子序列

    题意:题目太长没看,直接看输入输出猜出是最长下降子序列 用了以前的代码直接a了,做法类似贪心,把最小的顺序数存在数组里面,每次二分更新数组得出最长上升子序列 #include<iostream& ...

  4. POJ 1887:Testing the CATCHER 求递减序列的最大值

    Testing the CATCHER Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16131   Accepted: 5 ...

  5. poj1887 Testing the CATCHER

    Testing the CATCHER Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 13968   Accepted: 5 ...

  6. POJ-1887 Testing the CATCHER(dp,最长下降子序列)

    Testing the CATCHER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16515 Accepted: 6082 ...

  7. POJ 1887 Testingthe CATCHER (LIS:最长下降子序列)

    POJ 1887Testingthe CATCHER (LIS:最长下降子序列) http://poj.org/problem?id=3903 题意: 给你一个长度为n (n<=200000) ...

  8. UVa 231 - Testing the CATCHER

    题目大意:一种拦截导弹能拦截多枚导弹,但是它在每次拦截后高度不会再升高,给出导弹的序列,问最多能拦截多少枚导弹? 最长递减子序列问题. #include <cstdio> #include ...

  9. 专题:DP杂题1

    A POJ 1018 Communication System B POJ 1050 To the Max C POJ 1083 Moving Tables D POJ 1125 Stockbroke ...

随机推荐

  1. import 何时使用 "" 和<> Objective-C

    Objective-C在这方面与C/C ++相似.引号是给local本地包含的文件的.(你需要指明相对现有文件的相对路径的).而对于尖括号来说,是一个全局路径. 一般情况下引号用在引用自己项目中的类的 ...

  2. python深浅拷贝问题

    Python中,对象的赋值,拷贝(深/浅拷贝)之间是有差异的,如果使用的时候不注意,就可能产生意外的结果. 下面本文就通过简单的例子介绍一下这些概念之间的差别. 一.对象赋值 又叫变量对对象的引用 l ...

  3. mysql IF语句使用

    类似于三元运算符 1)  IF(where,result1,result2) = where?result1:result2 例如 SELECT IF(1=1,1,2)    =>  1 2)  ...

  4. POJ 2486 Apple Tree (树形DP,树形背包)

    题意:给定一棵树图,一个人从点s出发,只能走K步,每个点都有一定数量的苹果,要求收集尽量多的苹果,输出最多苹果数. 思路: 既然是树,而且有限制k步,那么树形DP正好. 考虑1个点的情况:(1)可能在 ...

  5. SAP成都研究院郑晓霞:Shift Left Testing和软件质量保证的一些思考

    今天的文章来自Jerry的同事,曾经的搭档郑晓霞(Zheng Kate).郑晓霞是在Jerry心中是一位很有实力的程序媛,2011年从西安某软件公司跳槽到SAP成都研究院.当时,成都研究院的CRM团队 ...

  6. xcode或者mac自带颜色器选择rgb格式

    解决方法

  7. 你是猴子请来的逗比么!IT跳槽大事件

       3月招聘大战早已硝烟四起,互联网职场摇身一变成了跳蚤市场,猎头们告诉跳蚤们,跳不跳不是不问题,往哪儿跳才是重点,跳对了高薪期权都如过眼云烟.不过小编不得不说,劳资最痛恨那些跳槽的人啦!就因为加班 ...

  8. 远程文件拷贝(fastcopy为例)

    远程地址格式如下:\\IP地址\磁盘符号$\文件夹名称(如:127.0.0.1\\c$\\image)拷贝了image文件夹下面的所有文件,但是如果远程机器有密码的话要先在本机先输入远程的目标地址然后 ...

  9. django 第一次运行出错

    直接运行整个项目正常,直接运行url文件报错 报错内容: E:\Python\python.exe D:/Python储存文件/ceshiweb/ceshiweb/urls.pyTraceback ( ...

  10. mask rcnn和roi-align

    faster-rcnn的github源码中是round四舍五入 但kaiming he的ppt是直接取整 1.讲roi-align和roi-pooling区别并且详细阐述roi-align过程的博客: ...