题干:

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

题目大意:

n个士兵排队,问你最少需要出列几个人,才能使得剩下的每一个士兵要么向左看可以看到无穷远,要么向右看可以看到无穷远。定义无穷远,当且仅当那一个方向的所有人的身高都小于他。

解题报告:

求两边LIS然后n^2枚举分界点就可以了。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
double v[MAX];
int a[MAX],b[MAX];
int n;
int main()
{cin>>n;for(int i = 1; i<=n; i++) scanf("%lf",v+i),a[i] = b[i] = 1;for(int i = 1; i<=n; i++) {for(int j = 1; j<=i-1; j++) {if(v[i] > v[j]) a[i] = max(a[i],a[j] + 1);      }}for(int i = n; i>=1; i--) {for(int j = n; j>i; j--) {if(v[i] > v[j]) b[i] = max(b[i],b[j] + 1);     }}int ans = 0;for(int i = 1; i<=n; i++) {for(int j = i+1; j<=n; j++) {ans = max(ans,a[i] +b[j]);}}printf("%d\n",n - ans);return 0 ;
}

【POJ - 1836】Alignment(dp,LIS,最长上升子序列类问题)相关推荐

  1. 【CodeForces - 987C 】Three displays (dp,最长上升子序列类问题,三元组问题)

    题干: It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaik ...

  2. LCS最长公共子序列和LIS最长上升子序列——例题剖析

    一.LCS最长公共子序列 最长公共子序列(LCS)问题算法详解+例题(转换成LIS,优化为O(nlogn),看不懂你来打我) longest comment subsequence 模板题 longe ...

  3. 算法设计 - LCS 最长公共子序列最长公共子串 LIS 最长递增子序列

    出处 http://segmentfault.com/blog/exploring/ 本章讲解: 1. LCS(最长公共子序列)O(n^2)的时间复杂度,O(n^2)的空间复杂度: 2. 与之类似但不 ...

  4. POJ 1458 Common Subsequence DP LCS 最长公共子序列

    最长公共子序列,照抄<算法设计与分析导论>P138-140 设输入的两个字符串分别为a1,a2,```,am(串a) b1,b2,````,bn(串b) 设d(i,j)为字符串a1,a2, ...

  5. lis最长上升子序列o(nlogn)优化

    LIS的暴力算法 我们知道,LIS(最长上升子序列,最长下降子序列,最长不上升子序列,最长不下降子序列)如果按照最初得方法做,我们设置的状态f[i]表示i结尾的最长LIS的长度,在枚举每一个数的时候都 ...

  6. LIS 最长递增子序列

    前言 LIS 即 longest increasing string,最长递增子序列,可以是不连续的.例如 2 3 5 2 3 4 5 的最长递增子序列为{2,3,4,5},长度为4. 两种方法可以求 ...

  7. LIS最长上升子序列详解(动态规划、贪心+二分、树状数组)

    1.摘要: 关于LIS部分,本篇博客讲一下LIS的概念定义和理解,以及求LIS的三种方法,分别是O(n^2)的DP,O(nlogn)的二分+贪心法,以及O(nlogn)的树状数组优化的DP,最后附上几 ...

  8. 【HDU - 1257】最少拦截系统 (标解dp,贪心可过,最长上升子序列类问题)

    题干: 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来 ...

  9. LIS 最长递增子序列问题

    一,    最长递增子序列问题的描述 设L=<a1,a2,-,an>是n个不同的实数的序列,L的递增子序列是这样一个子序列Lin=<aK1,ak2,-,akm>,其中k1< ...

  10. nyoj 36 最长公共子序列 dp问题最长公共子序列 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 咱们就不拐弯抹角了,如题,需要你做的就是写一个程序,得出最长公共

    最长公共子序列 时间限制: 3000 ms  |  内存限制: 65535 KB 难度: 3 描述 咱们就不拐弯抹角了,如题,需要你做的就是写一个程序,得出最长公共子序列. tip:最长公共子序列也称 ...

最新文章

  1. 转:iFire:玩聚 SRBacks 自定义脚本及样式表
  2. JAVA_OA(八):springMVC对JDBC的操作小项目a
  3. Flutter:使用复选框进行下拉多选
  4. HDU - 3026 Chinese Chess(二分图的必经边)
  5. 使用CL_RS_WHERE创建dynamic SQL statement
  6. lisp 河道水面线计算_天然河道水面线计算的几种方法解剖.pdf
  7. IT学习--学习不一定要用在现实工作中
  8. linux java 文件夹创建失败_Linux文件夹文件创建、删除
  9. aes加密 java_Android逆向中记算法识别(aes、tea、md5)
  10. 英语学习笔记2019-11-08
  11. java 创建日程到期提醒_在便签提醒类APP排行中哪个软件可以定时提醒每日日程待办?...
  12. 数据-第10课-循环链表
  13. 世界地图中国地图高清版
  14. C#进行注册表项和键值操作
  15. Android Adapter详解
  16. wc,鹅厂码农最常用的三大编程语言,Java竟然没上榜!
  17. ios链接xcode跑自动化意外中断?可以用pyautogui试试
  18. 百兆以太网口通信速率_以太网发送速率(传输速率)和传播速率
  19. 云计算------容器部署情感分析
  20. 如何恢复小强中被修改的软件包

热门文章

  1. [转]Win7 系统安装VS2008没反应 点击安装一闪就没有反应 .
  2. 790. Domino and Tromino Tiling
  3. 第三章 随机变量的数字特征
  4. c语言子查询返回子菜单,T-SQL基础(三)之子查询与表表达式
  5. python封装模块_Python练手,封装日志模块,v2
  6. linux服务器每次重启卡住,运维如何解决Linux服务器重启后命令无法正常使用的问题...
  7. Java设计模式笔记(6)观察者模式
  8. php左侧菜单栏递归代码,js实现左侧菜单栏递归循环遍历
  9. 矩阵运算——平移,旋转,缩放
  10. 关于config_site.h文件【译】