南邮 OJ 1135 Missile
来源:互联网 发布:网络摄像头ip地址扫描 编辑:程序博客网 时间:2024/05/21 04:21
Missile
总提交 : 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;}}
- 南邮 OJ 1135 Missile
- 1135Missile
- Missile
- seeking missile
- NOJ 1135 Missile dp 最长上升子序列变形 双dp
- sicily 1685 Missile
- 拦截导弹(missile)
- Sicily 1685. Missile
- Sicily 1685 Missile
- Missile:双状态DP
- codeforces D. Missile Silos
- 1256: Nuclear Missile
- ds 5.2 Missile
- PKU 3700 Missile Defence System
- Heat-Seeking Missile Game Physics
- Codeforces 144D: Missile Silos
- Codeforces 144D Missile Silos
- POJ 3700 Missile Defence System
- cxf发布webservice
- 基本数据结构和算法回顾
- ubuntu之路——解决ubuntu+win8双系统循环进入启动界面导致无法启动win8的问题
- 流量水波浪效果,超级炫酷暖人
- iOS连载3
- 南邮 OJ 1135 Missile
- SSH 案例学习总结(二)
- HBase与MapReduce集成1-HBase2Hdfs
- java中Timer因修改系统时间致使任务被挂起的原因
- redis实现 spring-redis-data初学习
- Gradle 1.12用户指南翻译——第三十九章. IDEA 插件
- Struts1的工作处理流程
- Edison Ubilinux Access Point
- java 字节流与字符流的区别