Description

In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are aligned in a straight line in front of the captain. The captain is not satisfied with the way his soldiers are aligned; it is true that the soldiers are aligned in order by their code number: 1 , 2 , 3 , . . . , n , but they are not aligned by their height. The captain asks some soldiers to get out of the line, as the soldiers that remain in the line, without changing their places, but getting closer, to form a new line, where each soldier can see by looking lengthwise the line at least one of the line's extremity (left or right). A soldier see an extremity if there isn't any soldiers with a higher or equal height than his height between him and that extremity.

Write a program that, knowing the height of each soldier, determines the minimum number of soldiers which have to get out of line.

Input

On the first line of the input is written the number of the soldiers n. On the second line is written a series of n floating numbers with at most 5 digits precision and separated by a space character. The k-th number from this line represents the height of the soldier who has the code k (1 <= k <= n).

There are some restrictions: 
• 2 <= n <= 1000 
• the height are floating numbers from the interval [0.5, 2.5] 

Output

The only line of output will contain the number of the soldiers who have to get out of the line.

Sample Input

8
1.86 1.86 1.30621 2 1.4 1 1.97 2.2

Sample Output

4

题意是n个士兵站队,最终使得每个士兵的左边或者右边的人的身高都是一次下降的,求的是出队的最小人数即总人数减去最多剩余的人数;
可以先求出从左到右的递增子序列和从右到左的递增子序列;

代码如下:

#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
#define MAXN 1010
double s[MAXN];
int a[MAXN],b[MAXN];
int n;
int main()
{
while(cin>>n)
{
int i,j;
for(i=; i<=n; i++)
scanf("%lf",&s[i]);
a[]=;
for(i=; i<=n; i++) //从头开始计算最长的递增序列
{
a[i]=;
for(j=; j<i; j++)
{
if(s[i]>s[j]&&a[j]>=a[i])
a[i]=a[j]+;
}
}
b[n]=;
for(i=n-; i>=; i--) //从尾部计算最长的递增序列
{
b[i]=;
for(j=n; j>i; j--)
{
if(s[i]>s[j]&&b[j]>=b[i])
b[i]=b[j]+;
}
}
int maxn=-;//初始化max
for(i=; i<=n; i++)
{
for(j=i+; j<=n; j++)
{
if(a[i]+b[j]>maxn)
maxn=a[i]+b[j];
}
}
printf("%d\n",n-maxn);
}
return ;
}

Alignment--POJ1836的更多相关文章

  1. poj1836 Alignment

    Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 11707   Accepted: 3730 Descri ...

  2. POJ1836 - Alignment(LIS)

    题目大意 一队士兵排成一条直线,问最少出队几个士兵,使得队里的每个士兵都可以看到又端点或者左端点 题解 从左往右搞一遍LIS,然后从右往左搞一遍LIS,然后枚举即可... 代码: #include&l ...

  3. POJ1836 Alignment(LIS)

    题目链接. 分析: 从左向右求一遍LIS,再从右向左求一遍LIS,最后一综合,就OK了. 注意: 有一种特殊情况(详见discuss): 8 3 4 5 1 2 5 4 3 答案是:2 AC代码如下: ...

  4. POJ1836:Alignment(LIS的应用)

    题目链接:http://poj.org/problem?id=1836 题目要求: 给你n个数,判断最少去掉多少个数,从中间往左是递减的序列,往右是递增的序列 需注意的是中间可能为两个相同的值,如 1 ...

  5. Alignment trap 解决方法  【转 结合上一篇

    前几天交叉编译crtmpserver到arm9下.编译通过,但是运行的时候,总是提示Alignment trap,但是并不影响程序的运行.这依然很令人不爽,因为不知道是什么原因引起的,这就像一颗定时炸 ...

  6. ARMLinux下Alignment trap的一些测试 【转自 李迟的专栏 CSDN http://blog.csdn.net/subfate/article/details/7847356

    项目中有时会遇到字节对齐的问题,英文为“Alignment trap”,如果直译,意思为“对齐陷阱”,不过这个说法不太好理解,还是直接用英文来表达. ARM平台下一般是4字节对齐,可以参考文后的给出的 ...

  7. Multiple sequence alignment Benchmark Data set

    Multiple sequence alignment Benchmark Data set 1. 汇总: 序列比对标准数据集: http://www.drive5.com/bench/ This i ...

  8. POJ 1836 Alignment

    Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11450 Accepted: 3647 Descriptio ...

  9. cf.295.C.DNA Alignment(数学推导)

    DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  10. Alignment

    Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14547 Accepted: 4718 Descriptio ...

随机推荐

  1. hive操作

    1.创建hive分区表: create table invites (id int, name string) partitioned by (ds string) row format delimi ...

  2. 使用 Selenium

    Selenium 简介 Selenium 基本用法 Selenium 查找节点 Selenium 节点交互 Selenium 动作链 Selenium 执行 JavaScript Selenium 获 ...

  3. MyEclipse 10 下在线安装插件

    昨天不知道怎么就删除了电脑中的eclipse 我x,还原不回来了. 今天就安装了最新版本的myeclipse10,大家都知道,MyEclipse 中有一个烦人的 Software and Worksp ...

  4. JDBC批量执行executeBatch

    JDBC事务 在数据库中,所谓事务是指一组逻辑操作单元,使数据从一种状态变换到另一种状态.为确保数据库中数据的一致性,数据的操纵应当是离散的成组的逻辑单元:当它全部完成时,数据的一致性可以保持,而当这 ...

  5. String例子

    #include <string.h> class String{ public: String(const String& str); String(const char* st ...

  6. Cordova 3.3 开发环境搭建(视频)

    图文文章参见: http://www.cnblogs.com/mlzs/p/3332199.html 视频共享链接 百度:http://pan.baidu.com/s/1c0EHfqC

  7. pip安装python包出现Cannot fetch index base URL http://pypi.python.org/simple/

    pipinstall***安装python包,出现 Cannot fetch index base URL  http://pypi.python.org/simple /错误提示或者直接安装不成功. ...

  8. Egret的屏幕适配模式图示

    1 ShowAll 过长时,上边有边框 过短时,左右有边框 2 noScale 不会进行任何缩放 3 noBorder 过长时,裁减左右 过短时,裁减上下 4 fixedWidth 过长时,下方有边框 ...

  9. NET的堆和栈04,对托管和非托管资源的垃圾回收以及内存分配

    在" .NET的堆和栈01,基本概念.值类型内存分配"中,了解了"堆"和"栈"的基本概念,以及值类型的内存分配.我们知道:当执行一个方法的时 ...

  10. [Key] RegCure Pro

    Serial RegCure Pro  : 4A803-C4F23-422B6-1F3D6 http://www.paretologic.com/product/regcure-pro/