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. solr java demo 基础入门

      <!--solr的maven依赖--> <dependencies> <dependency> <groupId>org.apache.solr&l ...

  2. mybatis 之 parameterType="java.util.List"

    <!-- 添加 --> <insert id="saveBatchMemberRoleConnRepModel" parameterType="java ...

  3. Push rejected: Push master to origin/master was rejected /failed to push some refs to /git did not exit cleanly

    用studio提交代码报 Push rejected: Push master to origin/master was rejected 用TortiuseGit提交代码报下面错,(我是用这种方法解 ...

  4. IOS网络篇1之截取本地URL请求(NSURLProtocol)

    本文转载至 http://blog.csdn.net/u014011807/article/details/39894247 NSURLProtocol 是iOS中非常重要的一个部分,我们经常会在以下 ...

  5. ANDROID – TOOLBAR STEP BY STEP(转)

    今年(2014) 的 Google I/O 發表令多數人為之一亮的 Material Design,而 Google 也從「Google I/O 2014」 開始,大家也陸陸續續地看到其更新的 And ...

  6. IE(兼容问题)错误:缺少标识符 字符串或数字的解决

    在IE上遇到一个问题,缺少标识符 字符串或数字的解决. 问题是我的html页面在Firefox.chorme中运行正常,而在IE中老是报“缺少标识符 字符串或数字”的错误,原因: 这就是IE和Fire ...

  7. 分布式实时日志系统(二) 环境搭建之 flume 集群搭建/flume ng资料

    最近公司业务数据量越来越大,以前的基于消息队列的日志系统越来越难以满足目前的业务量,表现为消息积压,日志延迟,日志存储日期过短,所以,我们开始着手要重新设计这块,业界已经有了比较成熟的流程,即基于流式 ...

  8. ERROR 1045 (28000): Access denied for user 'mycat'@'localhost' (using password: YES)

    创建用户: mysql> grant all on db1.* to mycat@'%' identified by '123456'; Query OK, 0 rows affected (0 ...

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

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

  10. 前端代码在线调试&分享网站

    1.RunJs 2.CodePen 3.JsFiddle