题目大意:

给定一排人的身高,求踢出最少的人可以使队列身高如下形状:

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
/*

/*
/*#include <iostream>
#include<cstdio>
using namespace std;
int r_dp[1010];
int l_dp[1010];
double num[1010];
int maxn;
int main()
{
     int n;
     cin>>n;
     for(int i=1;i<=n;i++)
     {
          cin>>num[i];
          l_dp[i]=r_dp[i]=1;
     }
     maxn=0;
     for(int i=1;i<=n;i++)
     {
          maxn=0;
          for(int j=1;j<i;j++)
          {
                if(num[i]>num[j])
                    maxn=max(maxn,l_dp[j]);
          }
          l_dp[i]=maxn+1;
     }
     for(int i=n;i>=1;i--)
     {
           maxn=0;
           for(int j=n;j>i;j--)
           {
                if(num[i]>num[j])
                    maxn=max(maxn,r_dp[j]);
           }
           r_dp[i]=maxn+1;
     }
     for(int i=1;i<=n;i++)
        l_dp[i]=max(l_dp[i],l_dp[i-1]);
     for(int i=n;i>=1;i--)
        r_dp[i]=max(r_dp[i+1],r_dp[i]);
     maxn=0;
     for(int i=1;i<=n;i++)
     {
          maxn=max(maxn,r_dp[i+1]+l_dp[i]);
     }
     cout<<n-maxn<<endl;
    return 0;
}*/
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
        int n,i,j;
        double a[1010];
        int lenl[1010],lenr[1010];
        int maxn;
        cin>>n;
        for(i=0;i<n;i++)
            cin>>a[i];
            lenl[0]=1;
        for(i=1;i<n;i++)
        {
             maxn=0;
             for(j=0;j<i;j++)
             {
                   if(a[i]>a[j]&&maxn<lenl[j])
                    maxn=lenl[j];
             }
             lenl[i]=maxn+1;
        }
        lenr[n-1]=1;
        for(i=n-2;i>=0;i--)
        {
               maxn=0;
               for(j=i+1;j<n;j++)
               {
                     if(a[i]>a[j]&&maxn<lenr[j])
                        maxn=lenr[j];
               }
               lenr[i]=maxn+1;
        }
        maxn=0;
        for(i=0;i<n-1;i++)
        {
              for(j=i+1;j<n;j++)
              {
                    if(lenl[i]+lenr[j]>maxn)
                        maxn=lenl[i]+lenr[j];
              }
        }
        cout<<n-maxn<<endl;
}

poj 1836 Alignment相关推荐

  1. POJ 1836 Alignment

    有一排人,身高可能不同,现在有一个理想状态是这排的每个人向左或向右看没有被挡住视野(当遇到等高或更高的人时会被挡住),现在问最少让几人出列可以达到这个理想状态. 最少人出列,其实就是一个人数最多的理想 ...

  2. 【POJ - 1836】Alignment(dp,LIS,最长上升子序列类问题)

    题干: In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers ar ...

  3. POJ前面的题目算法思路【转】

    1000 A+B Problem 送分题 49% 2005-5-7 1001 Exponentiation 高精度 85% 2005-5-7 1002 487-3279 n/a 90% 2005-5- ...

  4. POJ 超详细分类

    POJ 各题算法 1000    A+B Problem            送分题     49%    2005-5-7 1001    Exponentiation         高精度   ...

  5. POJ的题目分类(两个版本)

    版本一: 简单题 1000A+B Problem 1001Exponentiation 1003 Hangover 1004 Financial Management 1005 I Think I N ...

  6. 南京大学计算机系本科生开放日,2018/7

    2018/7/26 环境 计算机系位于南大仙林校区,树很多,绿化不错. 开放日全程包食宿,食堂很好吃,南大国际会议中心的早餐更厉害. 外地学生住南大国际会议中心或中公汇悦酒店.南大国际会议中心标准双人 ...

  7. 1836:Alignment

    题目Alignment 大意: n个军人按他们的序号排成一列 现在挑出一些人,剩下的军人相对位置不变. 则剩下队列中的军人至少可以看到这个队的某一端(当从军人的位置到端点的位置,不存在比他高或者与其身 ...

  8. hdu与poj题目分类

    POJ 初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(po ...

  9. (精)【ACM刷题之路】POJ题目详细多角度分类及推荐题目

    POJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094) 初期: ...

最新文章

  1. 玩转用例设计:XMind2TestCase一个高效的测试用例设计解决方案
  2. 自行控制loadrunner的socket协议性能测试 (转)
  3. C语言中的#ifndef、#def、#endif等宏
  4. 吐血整理!这可能是最全的机器学习工具手册
  5. python3.6+qt designer一系列配置
  6. nssl1476-联【线段树】
  7. 如何设置电脑自动锁屏_这个手机锁屏密码竟可以根据时间而变化!密码每分钟都会发生改变...
  8. MQTT工作笔记0005---CONNECT控制报文2
  9. Redis系列(七)--Sentinel哨兵模式
  10. 长大了,烦恼就像是滔滔江水
  11. Python: 字符串
  12. Ajax实现页面自动刷新实例解析
  13. [OpenBMC] 快速上手OpenBMC的Redfish
  14. 论文中的MS流程01
  15. Java语言 Timer 定时器的四种使用方式
  16. Python 离散小波变换(DWT) pywt库
  17. (Anroid Studio)用简单代码实现BMI计算器并且将应用安装到手机上
  18. 用不可逆算法MD5进行加密后,如何进行登录验证
  19. 学习笔记之——Python中类和对象的理解
  20. python基于web的安装程序_python web.py安装使用

热门文章

  1. 给将要进入职场的同学 - 开发软件不是闭卷考试
  2. mysql 集群与主从_Mysql集群和主从
  3. JAVA进阶教学之(单链表数据结构)
  4. 照片识别出错_AI跨年龄人脸识别技术在跨年龄寻亲的应用简析
  5. html表格按钮相对位置不变,表格中如何使td或div相对定位在某一行上面
  6. linux复制文件夹到另一个目录_Linux|一个命令行统计给定目录中有多少个子目录,学浪计划...
  7. python定位元素在列表中的位置_python定位列表元素
  8. mysql scws_apache+mysql+php+scws+myft_scws编译安装全程记录
  9. 数学难题html5小游戏答案,小学数学难题讲解及答案
  10. leetcode 142 --- linked-list-cycle-ii