POJ 1836:Alignment
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 14492 | Accepted: 4698 |
Description
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
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
Sample Input
8
1.86 1.86 1.30621 2 1.4 1 1.97 2.2
Sample Output
4
题意是给出了一个序列,希望这个序列满足这个序列中的每一个数,要么是从左到右的最大值,要么是从右到左的最大值。现在不满足,需要从当前序列中抽走几个数重新排能满足上述的条件。
从左到右求一次递增,从右到左求一次递增。求在每一个数之内其从左到右+从右到左 递增序列的最大值。用总和相减即可。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; int num;
int l_dp[2000];
int r_dp[2000];
double value[2000]; int main()
{
int i,j,max_v;
scanf("%d",&num); for(i=1;i<=num;i++)
{
cin>>value[i];
l_dp[i]=1;
r_dp[i]=1;
}
max_v=0;
for(i=1;i<=num;i++)
{
max_v=0;
for(j=1;j<i;j++)
{
if(value[i]>value[j])
{
max_v=max(l_dp[j],max_v);
}
}
l_dp[j]=max_v+1;
} for(i=num;i>=1;i--)
{
max_v=0;
for (j = num; j > i; j--)
{
if(value[i]>value[j])
{
max_v=max(r_dp[j],max_v);
}
}
r_dp[j]=max_v+1;
}
for(i=1;i<=num;i++)
{
l_dp[i]=max(l_dp[i],l_dp[i-1]);
}
for(i=num;i>=1;i--)
{
r_dp[i]=max(r_dp[i],r_dp[i+1]);
}
max_v=0;
for(i=1;i<=num;i++)
{
max_v = max(l_dp[i]+r_dp[i+1],max_v);
} cout<<num-max_v<<endl;
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 1836:Alignment的更多相关文章
- POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)
http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
- poj 1836 Alignment(dp)
题目:http://poj.org/problem?id=1836 题意:最长上升子序列问题, 站队,求踢出最少的人数后,使得队列里的人都能看到 左边的无穷远处 或者 右边的无穷远处. 代码O(n^2 ...
- POJ 1836 Alignment 水DP
题目: http://poj.org/problem?id=1836 没读懂题,以为身高不能有相同的,没想到排中间的两个身高是可以相同的.. #include <stdio.h> #inc ...
- poj 1836 Alignment(线性dp)
题目链接:http://poj.org/problem?id=1836 思路分析:假设数组为A[0, 1, …, n],求在数组中最少去掉几个数字,构成的新数组B[0, 1, …, m]满足条件B[0 ...
- POJ 1836 Alignment(DP max(最长上升子序列 + 最长下降子序列))
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14486 Accepted: 4695 Descri ...
- POJ 1836 Alignment 最长递增子序列(LIS)的变形
大致题意:给出一队士兵的身高,一开始不是按身高排序的.要求最少的人出列,使原序列的士兵的身高先递增后递减. 求递增和递减不难想到递增子序列,要求最少的人出列,也就是原队列的人要最多. 1 2 3 4 ...
- POJ 1836 Alignment --LIS&LDS
题意:n个士兵站成一排,求去掉最少的人数,使剩下的这排士兵的身高形成“峰形”分布,即求前面部分的LIS加上后面部分的LDS的最大值. 做法:分别求出LIS和LDS,枚举中点,求LIS+LDS的最大值. ...
- POJ 1836 Alignment
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11450 Accepted: 3647 Descriptio ...
随机推荐
- 编程题目 定义栈的数据类型,请在类型中实现一个能够得到栈最小元素的minx函数。
首先自己用 节点 实现了 栈 这种数据类型 为了实现题目了要求,我使用的两个栈. 一个栈 用来 push pop 用户的数据, 另外一个栈用来存放 最小元素(涉及元素比较) 代码如下: #!/usr/ ...
- node - DeprecationWarning: Mongoose: `findOneAndUpdate()` and `findOneAndDelete()` without the `use
1, 原因是因为:findOneAndUpdate()内部会使用findAndModify驱动,驱动即将被废弃,所以弹出警告!附上官方解释:Mongoose v5.5.8: Depre ...
- html基础与入门
html就是指一个html文件,它是由各种标签组成的 html分为 < !DOCTYPE html > 和 Head 和 Body Head title+meta+link+style B ...
- 048、Java中使用switch判断
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- 【转载】UnityWebRequest的初步使用及常用方法解析
文章来源:https://blog.csdn.net/qwe25878/article/details/85051911#_35 今天,来学习一下Unity新的网络请求方式UnityWebReques ...
- ACM-最优配餐
题目描述: 最优配餐 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 栋栋最近开了一家餐饮连锁店,提供外卖服务.随着连锁店越来越多,怎么合理的给客户送餐成为了一个急需解决的问 ...
- duilib之重写BUTTON按钮
在使用BUTTON过程中,有时候发现一些属性不够用,或要从新绘制BUTTON按钮,那该如何操作?其实很简单,只需要继承CButtonUI类就行. 创建类CMyButtonUI,继承CButtonUI, ...
- JS - 音频的播放和暂停
$(".gameSound").bind("click",function() { var audio = document.g ...
- Biu一Biu--GDB
gcc常见编译选项 ** -c **:只激活预处理.编译和汇编,也就是生成obj文件 ** -S **:只激活处理和编译,把文件编译成汇编代码 ** -o **:定制目标名称,缺省的时候编译出来的可执 ...
- 三十四、在SAP的屏幕选择中,将英文替换成我们想要的文本内容
一.我们在代码中定义了一个选择屏幕,但是对应的显示界面为英文 界面如下 二.我们选择[转到]-[文本元素] 三.默认的文本内容是问号和三个点 四.我们修改成我们需要的,并激活这个文本,如果不激活会丢失 ...