Alignment
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 14492   Accepted: 4698

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 <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; int num;
int l_dp[2000];
int r_dp[2000];
double value[2000]; int main()
{
int i,j,max_v;
scanf("%d",&num); for(i=1;i<=num;i++)
{
cin>>value[i];
l_dp[i]=1;
r_dp[i]=1;
}
max_v=0;
for(i=1;i<=num;i++)
{
max_v=0;
for(j=1;j<i;j++)
{
if(value[i]>value[j])
{
max_v=max(l_dp[j],max_v);
}
}
l_dp[j]=max_v+1;
} for(i=num;i>=1;i--)
{
max_v=0;
for (j = num; j > i; j--)
{
if(value[i]>value[j])
{
max_v=max(r_dp[j],max_v);
}
}
r_dp[j]=max_v+1;
}
for(i=1;i<=num;i++)
{
l_dp[i]=max(l_dp[i],l_dp[i-1]);
}
for(i=num;i>=1;i--)
{
r_dp[i]=max(r_dp[i],r_dp[i+1]);
}
max_v=0;
for(i=1;i<=num;i++)
{
max_v = max(l_dp[i]+r_dp[i+1],max_v);
} cout<<num-max_v<<endl;
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

最新文章

  1. MicroCube 风力发电装置
  2. HTTP协议 概述
  3. 项目开发中常用到的SQL语句
  4. Dorado事件的参数
  5. SurfaceFlinger
  6. bootstrap base css 基本css
  7. ASP.NET MVC+Knockout+Web API+SignalR
  8. UnityShader-菲涅尔反射(Fresnel Reflection)
  9. Win7如何分享局域网并设置共享文件夹账户和密码
  10. zookeeper集群配置详细教程
  11. selenium的基本用法
  12. [福建集训2011][LOJ10111]相框
  13. Linux中断处理(二)
  14. PI SQL 语句
  15. web 前端 转盘界面
  16. IOI 2017 Practice Contest mountains
  17. schedule和scheduleAtFixedRate的区别
  18. python第一个程序--&gt;hello world
  19. IpmiTool常见问题解决办法
  20. 基本算法思想之递推算法思想(C++语言描述)

热门文章

  1. GNS3 模拟DHCP之地址请求
  2. jsp获取web的跟路径
  3. DevOps - 工程师职责
  4. Spring Aop 原理分析
  5. Asp.net MVC中表单验证属性的使用
  6. 【SQL必知必会笔记(1)】数据库基础、SQL、MySQL8.0.16下数据库、表的创建及数据插入
  7. List实体类、DataTable与xml互转
  8. UVA 10564 计数DP
  9. MFC 屏蔽esc跟enter键
  10. JS最新最细面试题