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

  1. 8
  2. 1.86 1.86 1.30621 2 1.4 1 1.97 2.2

Sample Output

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

代码如下:

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<cstring>
  4. using namespace std;
  5. #define MAXN 1010
  6. double s[MAXN];
  7. int a[MAXN],b[MAXN];
  8. int n;
  9. int main()
  10. {
  11. while(cin>>n)
  12. {
  13. int i,j;
  14. for(i=; i<=n; i++)
  15. scanf("%lf",&s[i]);
  16. a[]=;
  17. for(i=; i<=n; i++) //从头开始计算最长的递增序列
  18. {
  19. a[i]=;
  20. for(j=; j<i; j++)
  21. {
  22. if(s[i]>s[j]&&a[j]>=a[i])
  23. a[i]=a[j]+;
  24. }
  25. }
  26. b[n]=;
  27. for(i=n-; i>=; i--) //从尾部计算最长的递增序列
  28. {
  29. b[i]=;
  30. for(j=n; j>i; j--)
  31. {
  32. if(s[i]>s[j]&&b[j]>=b[i])
  33. b[i]=b[j]+;
  34. }
  35. }
  36. int maxn=-;//初始化max
  37. for(i=; i<=n; i++)
  38. {
  39. for(j=i+; j<=n; j++)
  40. {
  41. if(a[i]+b[j]>maxn)
  42. maxn=a[i]+b[j];
  43. }
  44. }
  45. printf("%d\n",n-maxn);
  46. }
  47. return ;
  48. }

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. 在 Ubuntu 中安装 MySQL 指南

    安装MySQL 在Ubuntu上可以使用Ubuntu Software Center或者apt命令来安装MySQL,两种方式都十分方便. 1. 使用Ubuntu Software Center:打开U ...

  2. 分布式计算开源框架Hadoop入门实践

    目录(?)[+] Author :岑文初 Email: wenchu.cenwc@alibaba-inc.com msn: cenwenchu_79@hotmail.com blog: http:// ...

  3. Repeater的j简单使用

    嘿嘿,今天没有任务,所以突然想起来我之前记得笔 记说要把repeater的使用以及获取值的详细使用总结一下,所以这就闲来无聊总结一下,虽然现在不会使用这些小知识点的,但是我感觉自己的学习还是要 不断地 ...

  4. MVC的简单分页【转】

    传值的方式是通过querystring. 本例子是把整需要的数据查出来再分页的,因为当时做的时候数据很少,只有几十条. 如果数据多的话,可以在存储过程里分页,只是要传页码和记录的条数过来. 控制器: ...

  5. Masonry — 使用纯代码进行iOS应用的autolayout自适应布局

    本文转载至   http://www.ios122.com/2015/09/masonry/ 简化iOS应用使用纯代码机型自适应布局的工作,使用一种简洁高效的语法替代NSLayoutConstrain ...

  6. QT之 Hello World

    下载……   我下载的Qt creater 版本为4.2.1,Qt版本为5.8.0 打开QT Creater 1. 新建项目 New Project -> Application -> Q ...

  7. WEB-DICT词库计划

    欢迎大家支持晓阳童鞋的词库计划,建立一个庞大的中文词库 地址如下:http://webdict.info/ 什么是WEB-DICT词库计划? WEB-DICT词表计划目标是通过机器学习算法以及人工标注 ...

  8. 架设FTP Server-Windows Server 2012

    架设FTP Server-Windows Server 2012 https://jingyan.baidu.com/article/03b2f78c75b9b65ea237ae84.html   在 ...

  9. 【数据库系列】MySql中的select的锁表范围

    由于InnoDB预设的是Row-Level Lock,只有明确指定主键的时候MySql才会执行Row lock,否则MySql将会执行Table Lock. 1.明确指定主键则是行锁 2.明确指定主键 ...

  10. 字符乱码 导致 ORA-12899: value too large

    问题场景: 1.创建测试表 create table t01(name varchar2(30)) 2.插入数据 SQL> insert into t01 (name) values('所有分销 ...