Alignment
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 13319   Accepted: 4282

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

  1. 8
  2. 1.86 1.86 1.30621 2 1.4 1 1.97 2.2

Sample Output

  1. 4

Source

Romania OI 2002

题目要求:给出n个人排成一排。踢出一些人。让每一个人都能看到最左端,或最后端,最小的踢出人数是?

计算出正序和倒序的最长上升子序列,然后统计:有两种可能。一种是当中一个人是中间。那个人的身高最高。还有事两个人的身高同样。这两个人位置在中间,统计出最长的可能出现的队伍长度,计算出最小的踢出人数

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. using namespace std;
  5. int dp1[1200] , dp2[1200] ;
  6. double h[1200] ;
  7. int main()
  8. {
  9. int i , j , n , min1 ;
  10. while(scanf("%d", &n)!=EOF)
  11. {
  12. min1 = 1200 ;
  13. h[0] = 0 ; h[n+1] = 0 ;
  14. for(i = 1 ; i <= n ; i++)
  15. scanf("%lf", &h[i]);
  16. memset(dp1,0,sizeof(dp1));
  17. for(i = 1 ; i <= n ; i++)
  18. {
  19. for(j = 0 ; j < i ; j++)
  20. if( h[j] < h[i] && dp1[j]+1 > dp1[i] )
  21. dp1[i] = dp1[j]+1 ;
  22. }
  23. memset(dp2,0,sizeof(dp2));
  24. for(i = n ; i >= 1 ; i--)
  25. {
  26. for(j = n+1 ; j > i ; j--)
  27. if( h[j] < h[i] && dp2[j]+1 > dp2[i] )
  28. dp2[i] = dp2[j]+1 ;
  29. }
  30. for(i = 1 ; i <= n ; i++)
  31. {
  32. for(j = i ; j <= n ; j++)
  33. {
  34. if(i == j)
  35. min1 = min(min1,n-(dp1[i]+dp2[j]-1) );
  36. else
  37. min1 = min(min1, n-( dp1[i]+dp2[j] ) );
  38. }
  39. }
  40. printf("%d\n", min1);
  41. }
  42. }

poj1836--Alignment(dp,最长上升子序列变形)的更多相关文章

  1. 洛谷 P1020 导弹拦截(dp+最长上升子序列变形)

    传送门:Problem 1020 https://www.cnblogs.com/violet-acmer/p/9852294.html 讲解此题前,先谈谈何为最长上升子序列,以及求法: 一.相关概念 ...

  2. poj1159--Palindrome(dp:最长公共子序列变形 + 滚动数组)

    Palindrome Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 53414   Accepted: 18449 Desc ...

  3. uva 10131 Is Bigger Smarter ? (简单dp 最长上升子序列变形 路径输出)

    题目链接 题意:有好多行,每行两个数字,代表大象的体重和智商,求大象体重越来越大,智商越来越低的最长序列,并输出. 思路:先排一下序,再按照最长上升子序列计算就行. 还有注意输入, 刚开始我是这样输入 ...

  4. hdu 1025 dp 最长上升子序列

    //Accepted 4372 KB 140 ms //dp 最长上升子序列 nlogn #include <cstdio> #include <cstring> #inclu ...

  5. DP——最长上升子序列(LIS)

    DP——最长上升子序列(LIS) 基本定义: 一个序列中最长的单调递增的子序列,字符子序列指的是字符串中不一定连续但先后顺序一致的n个字符,即可以去掉字符串中的部分字符,但不可改变其前后顺序. LIS ...

  6. ACM: 强化训练-Beautiful People-最长递增子序列变形-DP

    199. Beautiful People time limit per test: 0.25 sec. memory limit per test: 65536 KB input: standard ...

  7. hdu 1080 dp(最长公共子序列变形)

    题意: 输入俩个字符串,怎样变换使其所有字符对和最大.(字符只有'A','C','G','T','-') 其中每对字符对应的值如下: 怎样配使和最大呢. 比如: A G T G A T G -  G ...

  8. hdu1503 最长公共子序列变形

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1503 题意:给出两个字符串 要求输出包含两个字符串的所有字母的最短序列.注意输出的顺序不能 ...

  9. HOJ Recoup Traveling Expenses(最长递减子序列变形)

    A person wants to travel around some places. The welfare in his company can cover some of the airfar ...

随机推荐

  1. Lisp学习:这是本质与应用?

    The Common Lisp Programming Language "The programming language of choice for those who set out ...

  2. 安装windows7导致Ubuntu启动项消失的问题的解决

    系统原来是Ubuntu14,前两天安装win7后,启动直接是win7.也就是Ubuntu的启动项消失了. 在windows下尝试非常多方法,都以失败告终,最后选择Ubuntu下boot-repair软 ...

  3. android HorizontalListView

    最近搞android 用到一个HorizontalListView 网上搜了一把.有一些国人实现的.但也有一些基本上是cp人家的开源项目. 本人找了两个.记录一下. 其一:https://github ...

  4. 时间戳timestamp

    1 时间戳 数据库中自动生成的 唯一的 二进制的数据,通常用作给数据表的行添加版本戳的机制. timestamp与时间和日期无关. timestamp存储大小为8字节. 一个数据表只能有一个times ...

  5. [Unity3D]Unity3D游戏开发之《愤慨的小鸟》弹弓实现

    各位朋友,大家晚上好, 我是秦元培.欢迎大家关注我的博客,我的博客地址是blog.csdn.net/qinyuanpei.今天我们来做一个高端大气上档次的东西. 我相信大家都玩过一款叫做<愤慨的 ...

  6. MSSQL- select @@identity的用法

    转载自:http://blog.163.com/zhangqian_sms/blog/static/544483382008925112539620/ 用select @@identity得到上一次插 ...

  7. Linux - 文件系统结构

    文件系统结构:   Linux文件系统为一个倒转的系统单根树状结构. 根为   / 严格区分大小写. 路径使用   /    分割,Windows使用  \     . 当前工作目录: 每一个Shel ...

  8. UVA - 12119 The Bells are Ringing (枚举)

    Perhaps you all have heard the mythical story about Tower of Hanoi (The details of this story is not ...

  9. DWZ (JUI) 教程(二):处理信息回馈的通用规范

    在开发过程中,抽象成模型,定义规范是非常有必要的,不仅可以简化代码,提高开发效率,也为自己减少了不少麻烦. 在开发中,因为DWZ这块是我负责,由于代码琐碎,重复度高,没有抽象封装,没有定义规范,别人不 ...

  10. Java字符串找出4个字节长度的字符

    不解释,直接上代码:  由于Iteye代码贴四个字节的UTF-8字符出错,特能图的方式发布几个特殊字符:  public class Byte4Check { public static void m ...