拦截导弹 |
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB |
Total submit users: 285, Accepted users: 190 |
Problem 10054 : No special judgement |
Problem description |
某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统。但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度。某天,雷达捕捉到敌国的导弹来袭。由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹。 |
Input |
输入数据为导弹依次飞来的高度,所有高度值均为不大于30000的正整数。 |
Output |
输出只有一行是这套系统最多能拦截的导弹数和要拦截所有导弹最少要配备这种导弹拦截系统的套数。两个数据之间用一个空格隔开. |
Sample Input |
389 207 155 300 299 170 158 65 |
Sample Output |
6 2 |
Problem Source |
NOI 99 |
CODE
/*
Name: 10054_导弹拦截
Copyright: yangchun's
Author: yangchun
Date: 15-06-08 19:58
Description: HUNAN UNIVERSITY ACM/ICPC Judge Online_Problem 10054_导弹拦截
Other: 求拦截系统数量的方法,就是求最长上升序列长度的高效方法!
*/
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int temp,max_len=1,_max_len=1;
vector <int> v1;
while(scanf("%d",&temp)!=EOF)
v1.push_back(temp);
int len = v1.size();
vector <int> v2(len,1);
vector <int> v3(len,1);
for(int i=1; i<len; i++)
{
for(int j=i-1; j>=0; j--)
{
if(v1[j] >= v1[i] && v2[j]+1 > v2[i])
{
v2[i] = v2[j]+1;
if(v2[i] > max_len) max_len = v2[i];
}
else if(v1[j] < v1[i] && v3[j]+1 > v3[i])
{
v3[i] = v3[j]+1;
if(v3[i] > _max_len) _max_len = v3[i];
}
}
}
printf("%d %d/n",max_len,_max_len);
return 0;
}