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

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

Source

Romania OI 2002

DP两遍LIS,
a1<a2<a3<.....<ai<=>ai+1>ai+2>ai+3>....a+n

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int getLIS(int* a,int len)
{
    int dp[1100],cnt=1;
    dp[0]=a[0];
    for(int i=1;i<len;i++)
    {
        if(dp[cnt-1]<a)
        {
            dp[cnt++]=a;
        }
        else
        {
            *lower_bound(dp,dp+cnt,a)=a;
        }
    }
    return cnt;
}

int main()
{
    int n;
    int a[1100],b[1100],c[1100],ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        double x;
        scanf("%lf",&x);
        a=x*100000;
    }
    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<=i;j++)
            b[j]=a[j];
        for(int j=n-1;j>i;j--)
            c[n-1-j]=a[j];
        ans=max(getLIS(b,i+1)+getLIS(c,n-i-1),ans);
    }
    printf("%d\n",n-ans);
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

POJ 1836 Alignment的更多相关文章

  1. poj 1836 Alignment(dp)

    题目:http://poj.org/problem?id=1836 题意:最长上升子序列问题, 站队,求踢出最少的人数后,使得队列里的人都能看到 左边的无穷远处 或者 右边的无穷远处. 代码O(n^2 ...

  2. POJ 1836 Alignment 水DP

    题目: http://poj.org/problem?id=1836 没读懂题,以为身高不能有相同的,没想到排中间的两个身高是可以相同的.. #include <stdio.h> #inc ...

  3. poj 1836 Alignment(线性dp)

    题目链接:http://poj.org/problem?id=1836 思路分析:假设数组为A[0, 1, …, n],求在数组中最少去掉几个数字,构成的新数组B[0, 1, …, m]满足条件B[0 ...

  4. POJ 1836 Alignment (双向DP)

    Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 10804   Accepted: 3464 Descri ...

  5. POJ 1836 Alignment(DP max(最长上升子序列 + 最长下降子序列))

    Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 14486   Accepted: 4695 Descri ...

  6. POJ 1836 Alignment 最长递增子序列(LIS)的变形

    大致题意:给出一队士兵的身高,一开始不是按身高排序的.要求最少的人出列,使原序列的士兵的身高先递增后递减. 求递增和递减不难想到递增子序列,要求最少的人出列,也就是原队列的人要最多. 1 2 3 4 ...

  7. POJ 1836 Alignment --LIS&LDS

    题意:n个士兵站成一排,求去掉最少的人数,使剩下的这排士兵的身高形成“峰形”分布,即求前面部分的LIS加上后面部分的LDS的最大值. 做法:分别求出LIS和LDS,枚举中点,求LIS+LDS的最大值. ...

  8. POJ - 1836 Alignment (动态规划)

    https://vjudge.net/problem/POJ-1836 题意 求最少删除的数,使序列中任意一个位置的数的某一边都是递减的. 分析 任意一个位置的数的某一边都是递减的,就是说对于数h[i ...

  9. poj 1836 LIS变形

    题目链接http://poj.org/problem?id=1836 Alignment Time Limit: 1000MS   Memory Limit: 30000K Total Submiss ...

随机推荐

  1. 学习笔记——Maven实战(四)基于Maven的持续集成实践

    Martin的<持续集成> 相信很多读者和我一样,最早接触到持续集成的概念是来自Martin的著名文章<持续集成>,该文最早发布于2000年9月,之后在2006年进行了一次修订 ...

  2. 优化Webstorm

    Webstorm这个编辑器还是很强大的,而且版本更新得快,支持最新的typescript,就是性能越来越低. 本文总结了一些优化Webstorm的有效方法,希望对大家有所帮助! 测试环境 Mac OS ...

  3. VmWare Workstation 10 安装 Ubuntu 14.04 问题解决

    Ubuntu安装过程很顺利,安装完成后还是有小问题存在   问题1:无法联网,PING可以通,网址无法解析 原因:默认DNS设置不正确 解决:设置DNS地址为8.8.8.8,问题解决   问题2:vm ...

  4. 解决方法:未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序

    win7或win8 64位调试程序,出现这样的错误提示:未在本地计算机上注册 Microsoft.Jet.OLEDB.4.0 提供程序 解决方法如下: 方法一:“设置应用程序池默认属性”/“常规”/” ...

  5. Android空闲教室查询-资料

    这是去年某课程的一个称作“研究型学习”的东西的报告的展示PPT,有点失败的是这个APP的名字起得不太好……PPT上的功能都实现了,其他功能都没有.一年了,程序都忘差不多了,也暂时没有时间分享.就先把P ...

  6. 【MPI学习3】MPI并行程序设计模式:不同通信模式MPI并行程序的设计

    学习了MPI四种通信模式 及其函数用法: (1)标准通信模式:MPI_SEND (2)缓存通信模式:MPI_BSEND (3)同步通信模式:MPI_SSEND (4)就绪通信模式:MPI_RSEND ...

  7. IT技术的进化道路

    IT技术是人类发明的,同时也是给人类服务的,这项技术的进化,就是距离人越来越近,大体上是: 大型机时代: 离人类的距离超过100米. 小型机时代: 离人类的距离前进到10米. PC机时代: 离人类的距 ...

  8. mysqld参数配置

    这个文件超级大, 查了一下, 大概的作用如下 是储存的格式INNODB类型数据状态下,ibdata用来储存文件的数据而库名的文件夹里面的那些表文件只是结构而已 由于mysql4.1默认试innodb, ...

  9. 第四次个人作业--必应词典(PC端)分析

    part.1 调研.评测 ·bug简述: 1.初始使用时,我觉得划译功能很方便,可是在QQ和浏览器上多次使用划译功能后,我发现并不是每次划译总会做出翻译,而是显示原文而已.如下图: 2.敲代码是出现b ...

  10. Easyui使用记录

    一天就这搞了这几行. 1. if else 可以嵌套: 2. 子页面调用父页面js,需要使用top.父页面js的方法. <script type="text/javascript&qu ...