poj1836--Alignment(dp,最长上升子序列变形)

时间:2021-09-24 21:17:58
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

8
1.86 1.86 1.30621 2 1.4 1 1.97 2.2

Sample Output

4

Source

Romania OI 2002

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

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

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int dp1[1200] , dp2[1200] ;
double h[1200] ;
int main()
{
int i , j , n , min1 ;
while(scanf("%d", &n)!=EOF)
{
min1 = 1200 ;
h[0] = 0 ; h[n+1] = 0 ;
for(i = 1 ; i <= n ; i++)
scanf("%lf", &h[i]);
memset(dp1,0,sizeof(dp1));
for(i = 1 ; i <= n ; i++)
{
for(j = 0 ; j < i ; j++)
if( h[j] < h[i] && dp1[j]+1 > dp1[i] )
dp1[i] = dp1[j]+1 ;
}
memset(dp2,0,sizeof(dp2));
for(i = n ; i >= 1 ; i--)
{
for(j = n+1 ; j > i ; j--)
if( h[j] < h[i] && dp2[j]+1 > dp2[i] )
dp2[i] = dp2[j]+1 ;
}
for(i = 1 ; i <= n ; i++)
{
for(j = i ; j <= n ; j++)
{
if(i == j)
min1 = min(min1,n-(dp1[i]+dp2[j]-1) );
else
min1 = min(min1, n-( dp1[i]+dp2[j] ) );
}
}
printf("%d\n", min1);
}
}

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

  1. 洛谷 P1020 导弹拦截&lpar;dp&plus;最长上升子序列变形&rpar;

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

  2. poj1159--Palindrome(dp&colon;最长公共子序列变形 &plus; 滚动数组)

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

  3. uva 10131 Is Bigger Smarter &quest; &lpar;简单dp 最长上升子序列变形 路径输出&rpar;

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

  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&colon; 强化训练-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&lpar;最长递减子序列变形&rpar;

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

随机推荐

  1. 1&period;7&period;4 Query Syntax and Parsing

    1. 查询语法和解析 这部分主要说明了如何指定被使用的查询解析器.同样描述了主查询解析器的支持的语法和功能.同时还描述了在特定环境下使用的其他查询解析器.这里有一些普通查询解析器都能使用的参数,将会在 ...

  2. 写sql语句注意事项

    做管理系统的,无论是bs结构的还是cs结构的,都不可避免的涉及到数据库表结构的设计,sql语句的编写等.因此在开发系统的时候,表结构设计是否合理,sql语句是否标准,写出的sql性能是否优化往往会成为 ...

  3. 【Android 多媒体开发】 MediaPlayer 状态机 接口 方法 解析

    作者 : 韩曙亮 转载请著名出处 :  http://blog.csdn.net/shulianghan/article/details/38487967 一. MediaPlayer 状态机 介绍 ...

  4. xcode6 iOS sdk8&period;1隐藏系统状态栏

    在代码项目(uzplayer)从iOS6升级到iOS8之后,头发如今视频播放器有.系统状态栏后面的背景: 这样就会导致有的时候按下Donebutton,或者拖滑块没有效果 所以,我们须要想个办法.把这 ...

  5. springMVC和spring上下文的关系

    springMVC继承了spring的servletcontext上下文, 所以, controller里的@Resource注入可以用以下替代 @Resource private IUserServ ...

  6. Sql Server 获取本周周一

    SELECT DATEADD(Day,(@i+1)-(DATEPART(Weekday,getdate())+@@DATEFIRST-1)%7,getdate())

  7. javascript如何从tr中分别获得每个td的元素

    <html> <body> <table border="1" id="table1"> <tr id="r ...

  8. Lintcode 730 所有子集的和

    已知: 给一整数 n, 我们需要求前n个自然数形成的集合的所有可能子集中所有元素的和. 示例: 给出 n = , 返回 可能的子集为 {{}, {}, {, }}. 子集的元素和为 + + + = 给 ...

  9. 利用optparse模块解析指令的字符串

    optparse模块主要用来为脚本传递命令参数,采用预先定义好的选项来解析命令行参数. 使用方法: 生成OptionParser对象,为对象添加option,用parse_args方法解析文字 具体实 ...

  10. 863&period; All Nodes Distance K in Binary Tree

    /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...