Alignment
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 11707   Accepted: 3730

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

[Submit]   [Go Back]   [Status]   [Discuss]

最近在进行动态规划的专题练习。。。

题意:令到原队列的最少士兵出列后,使得新队列任意一个士兵都能看到左边或者右边的无穷远处。

可以是递增序列。也可以是递减序列。更可以是如下图:

所以这是双向lis问题,刚开始的时候还没想到是lis问题,就按照自己的方法做。结果wa。后来发现有很多bug。。

看了discuss才想到是lis问题。还是练得少呀!!

#include<cstdio>
#include<cstring>
int dp1[1006]; //dp1[i]代表以i结尾的最长上升子序列
int dp2[1006]; //dp2[i]代表以i开始的最长下降子序列
int maxdp[1006]; //maxdp[i]代表以0~i中dp1中的最最大值
double p[1006];
int Max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int n,i,j,mm;
while(scanf("%d",&n)!=EOF)
{
mm = 0;
for(i=1;i<=n;i++)
scanf("%lf",&p[i]);
maxdp[1] = dp1[1] = 1;
maxdp[0] = 0;
for(i=2;i<=n;i++) //两个lis算法
{
dp1[i] = 1;
for(j=1;j<i;j++)
{
if(p[j]<p[i])
dp1[i] = Max(dp1[i],dp1[j]+1); }
maxdp[i] = Max(maxdp[i-1],dp1[i]);
}
dp2[n] = 1;
for(i=n-1;i>=1;i--)
{
dp2[i] = 1;
for(j=n;j>i;j--)
{
if(p[j]<p[i])
dp2[i] = Max(dp2[i],dp2[j]+1); }
mm = Max(mm,maxdp[i]+dp2[i+1]); //把以i前面的上升序列最大值和以i+1结尾的最长下降子序
//列长度加起来和前面对比,这样就是把全部的情况都算了一遍
} printf("%d\n",n-mm);
}
return 0;
}

poj1836 Alignment的更多相关文章

  1. POJ1836 - Alignment(LIS)

    题目大意 一队士兵排成一条直线,问最少出队几个士兵,使得队里的每个士兵都可以看到又端点或者左端点 题解 从左往右搞一遍LIS,然后从右往左搞一遍LIS,然后枚举即可... 代码: #include&l ...

  2. POJ1836 Alignment(LIS)

    题目链接. 分析: 从左向右求一遍LIS,再从右向左求一遍LIS,最后一综合,就OK了. 注意: 有一种特殊情况(详见discuss): 8 3 4 5 1 2 5 4 3 答案是:2 AC代码如下: ...

  3. POJ1836:Alignment(LIS的应用)

    题目链接:http://poj.org/problem?id=1836 题目要求: 给你n个数,判断最少去掉多少个数,从中间往左是递减的序列,往右是递增的序列 需注意的是中间可能为两个相同的值,如 1 ...

  4. Alignment trap 解决方法  【转 结合上一篇

    前几天交叉编译crtmpserver到arm9下.编译通过,但是运行的时候,总是提示Alignment trap,但是并不影响程序的运行.这依然很令人不爽,因为不知道是什么原因引起的,这就像一颗定时炸 ...

  5. ARMLinux下Alignment trap的一些测试 【转自 李迟的专栏 CSDN http://blog.csdn.net/subfate/article/details/7847356

    项目中有时会遇到字节对齐的问题,英文为“Alignment trap”,如果直译,意思为“对齐陷阱”,不过这个说法不太好理解,还是直接用英文来表达. ARM平台下一般是4字节对齐,可以参考文后的给出的 ...

  6. Multiple sequence alignment Benchmark Data set

    Multiple sequence alignment Benchmark Data set 1. 汇总: 序列比对标准数据集: http://www.drive5.com/bench/ This i ...

  7. POJ 1836 Alignment

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

  8. cf.295.C.DNA Alignment(数学推导)

    DNA Alignment time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  9. Alignment

    Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14547 Accepted: 4718 Descriptio ...

随机推荐

  1. post与get的区别

    GET请求在URL中传送的参数大多数浏览器限制该长度为2kb的,而POST没有. GET比POST更不安全,因为参数直接暴露在URL上,所以不能用来传递敏感信息. GET参数通过URL传递,POST放 ...

  2. Excel日期处理

    short format = cell.getCellStyle().getDataFormat(); //其值为22 输入值类型为2018/6/28 17:25:48 if (format!=22) ...

  3. IEdevelopToolbar ie浏览器的css代码调试工具

    使用IEdevelopToolbar的“选择元素”工具(ctrl+b),选取你要内容的地方下方的DIV,我们就可以找到几个关键字

  4. tf.cast()

    一.函数 tf.cast() cast( x, dtype, name=None ) 将x的数据格式转化成dtype.例如,原来x的数据格式是bool, 那么将其转化成float以后,就能够将其转化成 ...

  5. Paxos Made Simple

    Paxos一致性算法——分布式系统中的经典算法,论文本身也有一段有趣的故事.一致性问题是分布式系统的根本问题之一,在论文中,作者一步步的加强最初一致性问题(2.1节提出的问题)的约束条件,最终导出了一 ...

  6. JFinal ORM和Hibernate简要对比

    1.JFinal采用ActiveRecord实现数据库操作支持,较Hibernate开发效率提升六到十倍. 2.JFinal ActiveRecord较Hibernate学习成本低,一小时内能上手开发 ...

  7. mybatis框架入门程序:演示通过mybatis实现数据库的查询操作

    我们现在工程基于的数据库见“https://www.cnblogs.com/wyhluckdog/p/10147754.html”这篇博文. 1.mybatis下载 mybatis的代码由githua ...

  8. Django模型之Meta详解

    Django模型类的Meta是一个内部类,它用于定义一些Django模型类的行为特性.而可用的选项大致包含以下几类 abstract 这个属性是定义当前的模型是不是一个抽象类.所谓抽象类是不会对应数据 ...

  9. 在windows系统下安装oracle 11g

     oracle 11g 安装在windows server 2012 系统下. 最近,需要配置数据库,要求在windows操作系统下,安装oracle 11g 数据库,因为以前没有安装过,所以成功后, ...

  10. IE8不支持数组的indexOf方法 如何解决

    转自:http://www.jbxue.com/article/8367.html 原因分析: 这是一个js bug, 在IE8下,js数组没有indexOf方法,会报错:而在其它浏览器下(Firef ...