Alignment
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 13465   Accepted: 4336

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
最长上升子序列变形。
题意: 一排士兵,要求对于每个士兵。至少保证左边或者右边的人身高单调递增。问满足要求最少要出去多少人。这个问题等价于 最多有多少个士兵能够按要求排成一列。扫两遍LIS ,枚举每个点 求 max(dp_l[i]+dp_r[j]);i:1 to n; j:i+1 to n; 
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cctype>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define ll long long
#define maxn 116
#define pp pair<int,int>
#define INF 0x3f3f3f3f
#define max(x,y) ( ((x) > (y)) ? (x) : (y) )
#define min(x,y) ( ((x) > (y)) ? (y) : (x) )
using namespace std;
int n,dp_l[1010],dp_r[1010];
double a[1010];
void solve()
{
for(int i=2;i<=n;i++)
for(int j=1;j<i;j++)
if(a[i]>a[j]&&dp_l[i]<=dp_l[j])
dp_l[i]=dp_l[j]+1;
for(int i=n-1;i>=1;i--)
for(int j=n;j>i;j--)
if(a[i]>a[j]&&dp_r[i]<=dp_r[j])
dp_r[i]=dp_r[j]+1;
int ans=-INF;
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
ans=max(ans,dp_l[i]+dp_r[j]);
printf("%d\n",n-ans);
}
int main()
{
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
{
dp_l[i]=1;
dp_r[i]=1;
scanf("%lf",&a[i]);
}
solve();
}
return 0;
}

POJ 1836-Alignment(DP/LIS变形)的更多相关文章

  1. poj 1836 Alignment(dp)

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

  2. UVA 437 巴比伦塔 【DAG上DP/LIS变形】

    [链接]:https://cn.vjudge.net/problem/UVA-437 [题意]:给你n个立方体,让你以长宽为底,一个个搭起来(下面的立方体的长和宽必须大于上面的长和宽)求能得到的最长高 ...

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

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

  4. POJ 1836 Alignment 水DP

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

  5. poj 1836 Alignment(线性dp)

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

  6. POJ 1836 Alignment --LIS&LDS

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

  7. POJ 1836 Alignment (双向DP)

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

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

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

  9. POJ 1836 Alignment

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

随机推荐

  1. bootm命令移植

    <bootm作用> 为linux内核的启动准备条件 <bootloader作用总结> (1)初始化软/硬件(内存硬件/外部设备/堆栈) (2)启动操作系统 <uImagi ...

  2. MSSQL 基础知识与语句笔记

    建库 CREATE DATABASE 数据库名 ON[PRIMARY] --默认属于PRIMARY主文件组,可省略 ( NAME='', --主数据文件的逻辑名 名称 FILEAME='', --主数 ...

  3. 【BZOJ 3036】 3036: 绿豆蛙的归宿 (概率DP)

    3036: 绿豆蛙的归宿 Time Limit: 2 Sec  Memory Limit: 128 MBSubmit: 491  Solved: 354 Description 随着新版百度空间的下线 ...

  4. [JOISC2014]歴史の研究/[BZOJ4241]历史研究

    [JOISC2014]歴史の研究/[BZOJ4241]历史研究 题目大意: 一个长度为\(n(n\le10^5)\)的数列\(A(A_i\le10^9)\),定义一个元素对一个区间\([l,r]\)的 ...

  5. RTSP交互过程

    步骤一: 发送:OPTIONS rtsp://127.0.0.1/172.30.31.225:8000:HIK-DS8000HC:0:1:admin:hs123456:av_stream RTSP/1 ...

  6. HDU 1890 Robotic Sort (splay tree)

    Robotic Sort Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  7. Bootstrap 3之美07-插件Collapse、Accordion、Modal、Tab、Tooltip、Alert、Carousel

    类似Page Header, Breadcrumbs, Dropdowns等,都是Bootstrap的组件,是静态的.如果涉及到交互,Bootstrap提供了插件.这些插件包括: ○ 过渡效果: bo ...

  8. mongodb 只查询一个字段

    db.users.find({}, {"userName":1,"_id":0}) ; "_id":0表示不显示_id

  9. JDBC连接oracle RAC数据库配置

    RAC的配置如下: node1:ip地址192.168.60.132,实例名:rac1,主机名:rac1 node2:ip地址192.168.60.144,实例名:rac2,主机名:rac2 RAC服 ...

  10. oracle转义符

    要使用_,则需要做如下转义 select column_name from user_tab_columns where table_name = 'SYS_TERMINAL_MAPPING' AND ...