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 ...
随机推荐
- springMVC 与 struts+hibernate+spring优缺点
springMVC: Spring 框架是高度可配置的,而且包含多种视图技术,例如 JavaServer Pages(JSP)技术.Velocity.Tiles.iText 和POI.Spring M ...
- leetcode395 Longest Substring with At Least K Repeating Characters
思路: 尺取法. 循环i:1~26,分别计算恰好包含i种字母并且每种字母出现的次数大于等于k个的最长子串长度. 没法直接使用尺取法,因为不满足区间单调性,但是使用如上的方法却是可以的,因为子串中包含的 ...
- mysql IF语句使用
类似于三元运算符 1) IF(where,result1,result2) = where?result1:result2 例如 SELECT IF(1=1,1,2) => 1 2) ...
- FZU 1977 Pandora adventure (插头DP,常规)
题意:有一个n*m矩阵,其中有些格子必走,有些格子不可走,其他格子是可走也可不走,问有多少条哈密顿回路? 思路: 本来是一道很简单的题,代码写多了连白痴bug都查不出了,竟然用i>=ex& ...
- 洛谷 P1311 选择客栈
题目描述 丽江河边有n 家很有特色的客栈,客栈按照其位置顺序从 1 到n 编号.每家客栈都按照某一种色调进行装饰(总共 k 种,用整数 0 ~ k-1 表示),且每家客栈都设有一家咖啡店,每家咖啡店均 ...
- cookie安全
www.baidu.com host 文件 定义 a.baidu.com 为127.0.01 本地编写php程序 读取浏览器发送给 a.baidu.com的cookie 会把 .baidu.com域下 ...
- 美可能排除中国大陆制造/生产的所有5G产品
https://www.wsj.com/articles/u-s-considers-requiring-5g-equipment-for-domestic-use-be-made-outside-c ...
- POI 读取 Excel 文件
import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.Out ...
- Bootstrap历练实例:响应式导航栏
响应式的导航栏 为了给导航栏添加响应式特性,您要折叠的内容必须包裹在带有 classes .collapse..navbar-collapse 的 <div> 中.折叠起来的导航栏实际上是 ...
- Cookies和Session的区别和理解
Cookies和Session的区别和理解 cookie机制 Cookies是服务器在本地机器上存储的小段文本并随每一个请求发送至同一个服务器.IETF RFC 2965 HTTP State Man ...