POJ 1836-Alignment(DP/LIS变形)
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 13465 | Accepted: 4336 |
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
最长上升子序列变形。
题意: 一排士兵,要求对于每个士兵。至少保证左边或者右边的人身高单调递增。问满足要求最少要出去多少人。这个问题等价于 最多有多少个士兵能够按要求排成一列。扫两遍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变形)的更多相关文章
- poj 1836 Alignment(dp)
题目:http://poj.org/problem?id=1836 题意:最长上升子序列问题, 站队,求踢出最少的人数后,使得队列里的人都能看到 左边的无穷远处 或者 右边的无穷远处. 代码O(n^2 ...
- UVA 437 巴比伦塔 【DAG上DP/LIS变形】
[链接]:https://cn.vjudge.net/problem/UVA-437 [题意]:给你n个立方体,让你以长宽为底,一个个搭起来(下面的立方体的长和宽必须大于上面的长和宽)求能得到的最长高 ...
- POJ 1836 Alignment 最长递增子序列(LIS)的变形
大致题意:给出一队士兵的身高,一开始不是按身高排序的.要求最少的人出列,使原序列的士兵的身高先递增后递减. 求递增和递减不难想到递增子序列,要求最少的人出列,也就是原队列的人要最多. 1 2 3 4 ...
- 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 --LIS&LDS
题意:n个士兵站成一排,求去掉最少的人数,使剩下的这排士兵的身高形成“峰形”分布,即求前面部分的LIS加上后面部分的LDS的最大值. 做法:分别求出LIS和LDS,枚举中点,求LIS+LDS的最大值. ...
- POJ 1836 Alignment (双向DP)
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10804 Accepted: 3464 Descri ...
- POJ 1836 Alignment(DP max(最长上升子序列 + 最长下降子序列))
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14486 Accepted: 4695 Descri ...
- POJ 1836 Alignment
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11450 Accepted: 3647 Descriptio ...
随机推荐
- luoguP4336 [SHOI2016]黑暗前的幻想乡 容斥原理 + 矩阵树定理
自然地想到容斥原理 然后套个矩阵树就行了 求行列式的时候只有换行要改变符号啊QAQ 复杂度为\(O(2^n * n^3)\) #include <cstdio> #include < ...
- BZOJ 2330 SCOI2011糖果 差分约束
2330: [SCOI2011]糖果 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2819 Solved: 820 题目连接 http://www ...
- windows下python2.7.14版本的安装
本文主要对window下如何安装Python进行图解说明 步骤一.从官网下载相应的版本(本文以2.7.14为例),https://www.python.org/downloads/release/py ...
- spring---aop(10)---Spring AOP中AspectJ
写在前面 在之前的文章中有写到,Spring在配置中,会存在大量的切面配置.然而在很多情况下,SpringAOP 所提供的切面类真的不是很够用,比如想拦截制定的注解方法,我们就必须扩展DefalutP ...
- SEEprog Serial EEPROM programmer
Features SEEprog is universal programmer of all types of serial EEPROMs in 8-pin package. SEEprog en ...
- sqlserver存储过程循环写法
用游标,和WHILE可以遍历您的查询中的每一条记录并将要求的字段传给变量进行相应的处理==================DECLARE @A1 VARCHAR(10),@A2 VARCHAR(10) ...
- 配置tomcat让shtml嵌套文件显示
之前,我知道tomcat可以直接解析shtml文件,在浏览器中显示效果来,后来由于需求发生改变,比如说 在做静态化生成的时候一个网站的头部和底部都是一样的,如果每个页面都生成一次,显然很浪费时间,所有 ...
- systemtap 2.8 安装说明书
systemtap: a linux trace/probe tool Visit the project web site at <http://sourceware.org/systemta ...
- 淘宝--印风 专注于MySQL内核代码
http://blog.csdn.net/zhaiwx1987/article/details/6113472?utm_source=jiancool
- 建议:一般地,建议使用xcode 4.3开发app 而不是使用xcode4.5
建议:一般地,建议使用xcode 4.3开发app 而不是使用xcode4.5 因为,xcode4.5 默认的sdk 是ios6.0,这里面有很多新特性.比如,Autolayout 等,这个特性再io ...