POJ 1887 Testing the CATCHER
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 13396 | Accepted: 4905 |
Description
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
Output
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的更多相关文章
- POJ 1887 Testing the CATCHER(LIS的反面 最大递减子序列)
Language: Default Testing the CATCHER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1 ...
- Poj 1887 Testing the CATCHER(LIS)
一.Description A military contractor for the Department of Defense has just completed a series of pre ...
- poj 1887 Testing the CATCHER_最长上升子序列
题意:题目太长没看,直接看输入输出猜出是最长下降子序列 用了以前的代码直接a了,做法类似贪心,把最小的顺序数存在数组里面,每次二分更新数组得出最长上升子序列 #include<iostream& ...
- POJ 1887:Testing the CATCHER 求递减序列的最大值
Testing the CATCHER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16131 Accepted: 5 ...
- poj1887 Testing the CATCHER
Testing the CATCHER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 13968 Accepted: 5 ...
- POJ-1887 Testing the CATCHER(dp,最长下降子序列)
Testing the CATCHER Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16515 Accepted: 6082 ...
- POJ 1887 Testingthe CATCHER (LIS:最长下降子序列)
POJ 1887Testingthe CATCHER (LIS:最长下降子序列) http://poj.org/problem?id=3903 题意: 给你一个长度为n (n<=200000) ...
- UVa 231 - Testing the CATCHER
题目大意:一种拦截导弹能拦截多枚导弹,但是它在每次拦截后高度不会再升高,给出导弹的序列,问最多能拦截多少枚导弹? 最长递减子序列问题. #include <cstdio> #include ...
- 专题:DP杂题1
A POJ 1018 Communication System B POJ 1050 To the Max C POJ 1083 Moving Tables D POJ 1125 Stockbroke ...
随机推荐
- Java 多个if 和多个else if 的区别
int a=1; if(a==1){System.out.println("1");} if(a==2){System.out.println("2");} i ...
- HDU4035 Maze(期望DP)
题意 抄袭自https://www.cnblogs.com/Paul-Guderian/p/7624039.html 有n个房间,由n-1条隧道连通起来,形成一棵树,从结点1出发,开始走,在每个结点i ...
- 2566. [51nod 1129] 字符串最大值
[题目描述] 一个字符串的前缀是指包含该字符第一个字母的连续子串,例如:abcd的所有前缀为a, ab, abc, abcd. 给出一个字符串S,求其所有前缀中,字符长度与出现次数的乘积的最大值. 例 ...
- 《Head First HTML与CSS》项目实践中学到的东西
1.组织的重要性. 首先是要建立两个根文件夹,一个存上线页面的资源,一个存测试页面的资源.所有改动内容都在测试页面的文件夹中进行,在这个文件夹中进行测试.W3C语法检测后(HTML检测网站:https ...
- WebService学习之旅(二)JAX-WS基于Web容器发布WebService
在上节中我们定义Web服务接口和实现类后,调用Endpoint类的静态方法publish发布来webservice,这种方法使用起来虽然简单,但是对于一个企业级应用来说通常对外提供的服务可能不止一个, ...
- KMP字符串模式匹配详解
KMP字符串模式匹配详解 http://www.cppblog.com/oosky/archive/2006/07/06/9486.html
- Dll加载总是出问题,显示无法加载
我从网上找了一个类似的问题,具体的内容如下 创建了个mfc的共享链接库,里面只有这样一个加法 _declspec(dllexport) int add(int a,int b){ return a+b ...
- MySQL检查死锁简介
- bsub && lsf 介绍
文章转载地址:http://www.bbioo.com/lifesciences/40-114265-1.html LSF系统介绍 http://scc.ustc.edu.cn/zh_CN/ 中科大超 ...
- NBUT 1115 Cirno's Trick (水)
题意: 给出多个double数,去掉其最小的和最大的,再对余下的求均值. 思路: 再输入时将最大和最小去掉,顺便统计非最值的和,输出时除一下个数即可. #include <bits/stdc++ ...