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. 【代码审计】EasySNS_V1.6远程图片本地化导致Getshell

    0x00 环境准备 EasySNS官网:http://www.imzaker.com 网站源码版本:EasySNS极简社区V1.60 程序源码下载:http://es.imzaker.com/inde ...

  2. Bypass X-WAF SQL注入防御(多姿势)

    0x00 前言 ​ X-WAF是一款适用中.小企业的云WAF系统,让中.小企业也可以非常方便地拥有自己的免费云WAF. ​ 本文从代码出发,一步步理解WAF的工作原理,多姿势进行WAF Bypass. ...

  3. Python 管理 MySQL

    Python MySQLdb 模块 Python pymysql 模块 Python SQLAlchemy 模块 Python ConfigParser 模块 Python 创建 MySQL 配置文件 ...

  4. C语言实现字符串IP与整数型IP的相互转换

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h&g ...

  5. react native (一)

    开始接触app方面的工作,真心塞~ 又开始了周而复始的死磕一个问题专坐一整天的节奏,关键是还没有成绩,实在无语.╮(╯▽╰)╭,还是总结一下最近心塞历程吧-- react native中文网:http ...

  6. php curl那点事儿

    curl是最常用功能之一初始化句柄 $ch = curl_init(); post 传$data 1. 如果$data是字符串,则Content-Type是application/x-www-form ...

  7. 虚拟机上的centos连不了外网,吧原来的配置信息改成如下就行(删除了一些多余的信息,变化:原来的ONBOOT的值是no)

    DEVICE=eth1BOOTPROTO=dhcpHWADDR=08:00:27:67:be:98ONBOOT=yes

  8. SqlServer 连接远程服务器数据库 实现跨服务器联合查询

    第一种: exec sp_addlinkedserver 'ITSV ', ' ', 'SQLOLEDB ', '远程服务器名或ip地址 ' exec sp_addlinkedsrvlogin 'IT ...

  9. MySQL使用查询结果生成临时表

    MySQL中不支持对同一个表使用其查询结果更新or删除本表内数据(也就是update或delete后的where条件为针对相同表的select),解决方案是创建临时表做过度保存中间数据: 可以直接使用 ...

  10. React组件设计(转)

    React组件设计 组件分类 展示组件和容器组件 展示组件 容器组件 关注事物的展示 关注事物如何工作 可能包含展示和容器组件,并且一般会有DOM标签和css样式 可能包含展示和容器组件,并且不会有D ...