南邮 OJ 1135 Missile

来源:互联网 发布:网络摄像头ip地址扫描 编辑:程序博客网 时间:2024/05/21 04:21

Missile

时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 65536 KByte
总提交 : 140            测试通过 : 43 

比赛描述

Long , long ago ,country A invented a missile system to destroy the missiles from their enemy . That system can launch only one missile to destroy multiple missiles if the heights of all the missiles form a non-decrease sequence .

But recently , the scientists found that the system is not strong enough . So they invent another missile system . The new system can launch one single missile to destroy many more enemy missiles . Basically , the system can destroy the missile from near to far . When the system is begun , it chooses one enemy missile to destroy , and then destroys a missile whose height is lower and farther than the first missile . The third missile to destroy is higher and farther than the second missile … the odd missile to destroy is higher and farther than the previous one , and the even missile to destroy is lower and farther than the previous one .

Now , given you a list of the height of missiles from near to far , please find the most missiles that can be destroyed by one missile launched by the new system .



输入

The input contains multiple test cases .

In each test case , first line is an integer n ( 0<n<=1000 ) , which is the number of missiles to destroy . Then follows one line which contains n integers ( <=109 ) , the height of the missiles followed by distance .

The input is terminated by n = 0 .

输出

       For each case , print the most missiles that can be destroyed in one line .

样例输入

4
5 3 2 4
3
1 1 1
0

样例输出

3
1

题目来源

NUPT ACM




//d[i]:1到i所能毁掉的最多导弹#include<iostream>#define N 1001using namespace std;int main(){int n,i,j,d[N],max_step;long h[N];while(cin>>n && n){max_step = 1;for(i=1;i<=n;++i){cin>>h[i];}d[1] = 1;for(i=2;i<=n;++i){d[i] = 1;for(j=i-1;j>0;--j){if(d[j]%2==0 && h[j]<h[i] && d[j]+1>d[i]){d[i] = d[j]+1;}if(d[j]%2==1 && h[j]>h[i] && d[j]+1>d[i]){d[i] = d[j]+1;}}if(max_step<d[i]){max_step = d[i];}}cout<<max_step<<endl;}}





0 0
原创粉丝点击