PKU 3700 Missile Defence System

Description

To play against the threats of malicious countries nearby, Country R has updated their missile defence system. The new type system can bring down a series of missiles as long as they are coming in ascending order by altitude or descending order by altitude.

Given the heights of a sequence of coming missiles, the general wants to know how many sets of the new type systems are needed to bring down all of them.

Input

The input consists of several test cases. The first line of each test case contains an integer n(1 ≤ n ≤ 50). The next line contains n different integers indicating the heights.

Output

For each test case output a single line containing the number of systems needed.

Sample Input

5
3 5 2 4 1
0
Sample Output

2


贪心+dfs

dfs很清楚,关键是贪心的部分。基本思想是

对于每一个元素,要么用增序来包含他,要么用降序来包含他。(dfs)

当用增序时,用一个比他小的,且最后一个最大(下界)的序列来包含他。(贪心)降序同理。

 


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值