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. SpringBoot 常见问题记录

    问题一 Error starting ApplicationContext. To display the auto-configuration report re-run your applicat ...

  2. Win10 快捷键

    Win + D # 最小化桌面 Win + L # 锁屏 Win + E # 打开"我的电脑" Win + I # 打开设置 Win + P # 启动投屏 Win + G # 屏幕 ...

  3. ip防刷脚本

    #!/bin/sh #防刷脚本 #env ACCESS_PATH=/home/wwwlogs ACCESS_LOG=y.log IPTABLES_TOP_LOG=iptables_top.log DR ...

  4. Charles抓包(iOS的http/https请求)

    Charles抓包(iOS的http/https请求) Charles安装 HTTP抓包 HTTPS抓包 1. Charles安装 官网下载安装Charles:https://www.charlesp ...

  5. 原:Myeclipse10+Egit+bitbucket实现版本控制

    1.首先在https://bitbucket.org注册账号,建立仓库(repository),这部分有问题的可以看https://confluence.atlassian.com/display/B ...

  6. jQuery Easing 动画效果扩展--使用Easing插件,让你的动画更具美感。

    jQuery  Easing 是一款比较老的jQuery插件,在很多网站都有应用,尤其是在一些页面滚动.幻灯片切换等场景应用比较多.它非常小巧,且有多种动画方案供选择,使用简单,而且免费. 引入Eas ...

  7. Win7/Win8/IIS7/IIS8配置ASP/ACCESS

    1.在IIS信息服务管理器配置好站点后,配置ASP属性: a.IIS启用ASP 1.打开控制面板>>程序和功能>>“打开或关闭windows功能”,见下图 2.稍等片刻,出现一 ...

  8. C# EF中调用 存储过程并调回参数

    TourEntities db = new TourEntities(); List<v_product> v = new List<v_product>(); SqlPara ...

  9. Android 请求运行时权限

    写文件到sd卡中,会报权限问题,需要动态申请申请运行时权限 1. MainActivity.java public class MainActivity extends Activity { priv ...

  10. vue项目打包之后页面空白解决办法

    之前项目遇到个情况,npm run build打包之后上传到服务器后,index.html打开一片空白,资源都加载了,但是就是不显示. 然后百度找了原因,修改了两处地方 一.修改 assetsPubl ...