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. 20145208 《Java程序设计》第9周学习总结

    20145208 <Java程序设计>第9周学习总结 教材学习内容总结 本周学习的内容有第十六周整合数据库,第十七章反射与类加载器,第十八章自定义泛型.枚举与注释. 在本周学习中,最大的难 ...

  2. SDAccel-FPGA将带来至多25倍单位功耗性能提升

    很久没有看FPGA了,本来想继续学习HLS,就上Xilinx的网站看了看.结果发现了SDx 开发环境,很新的一个东西.由于我对这方面了解不多,本篇博文仅仅只是资料的整合和介绍. 1.SDx开发环境 X ...

  3. Scala学习笔记(六):Scala程序

    想要编写能够独立运行的Scala程序,就必须创建有main方法(仅带一个参数Array[String],且结果类型为Unit)的单例对象. 任何拥有合适签名的main方法的单例对象都可以用来作为程序的 ...

  4. storm如何分配任务和负载均衡?

    背景 在上篇:storm的基础框架分析 基本探讨了storm的: worker.executor等组件的关系. 线程模型和消息系统. 任务分配流程. topology提交到执行的过程. 但,感觉对ni ...

  5. 『片段』C# DateTime 时间相减 和 时区的关系

    本文只是基础代码片段,直接先写 结论: C# DateTime 时间相减 —— 和 时区无关,只和时间值有关. 运行结果: 测试代码: using System; using System.Colle ...

  6. Android--多选自动搜索提示

    一. 效果图 常见效果,在搜素提示选中之后可以继续搜索添加,选中的词条用特殊字符分开 二. 布局代码 <MultiAutoCompleteTextView android:id="@+ ...

  7. javascript继承(六)—实现多继承

    在上一篇javascript继承—prototype最优两种继承(空函数和循环拷贝)(3) ,介绍了js较完美继承的两种实现方案,那么下面来探讨一下js里是否有多继承,如何实现多继承.在这里可以看看j ...

  8. 【团队项目演示】FZU5BOYS之团队项目链接汇总

    FZU5BOYS      项目冲刺之博客汇总 Alpha版本 Day One Day Two Day Three Day Four Day Five Day Six Day Seven Day Ei ...

  9. JDK的目录

    要想深入了解Java必须对JDK的组成, 本文对JDK6里的目录做了基本的介绍,主要还是讲解 了下JDK里的各种可执行程序或工具的用途 Java(TM) 有两个平台 JRE 运行平台,包括Java虚拟 ...

  10. iOS边练边学--父子控制器之自定义控制器的切换

    一.如图所示的界面,按钮One.Two.Three分别对应三个控制器的view,点击实现切换.个人感觉父子控制器的重点在于,控制器的view们之间建立了父子关系,控制器不建立的话,发生在view上面的 ...