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 ...
随机推荐
- tftp协议
<前言> 嵌入式开发是一个交叉开发的模式,需要将宿主机上的文件烧写到目标机上. 方式: JTAG USB 串口 网络 <tftp下载> 首先需要将宿主机架成一个TFTP的服务器 ...
- 递归与分治策略之循环赛日程表Java实现
递归与分治策略之循环赛日程表 一.问题描述 设有n=2^k个运动员要进行网球循环赛.现要设计一个满足以下要求的比赛日程表: (1)每个选手必须与其他n-1个选手各赛一次: (2)每个选手一天只能参赛一 ...
- [BZOJ5292][BJOI2018]治疗之雨(概率DP+高斯消元)
https://blog.csdn.net/xyz32768/article/details/83217209 不难找到DP方程与辅助DP方程,发现DP方程具有后效性,于是高斯消元即可. 但朴素消元显 ...
- wikioi 1434 孪生素数 水题、素数模版
1434 孪生素数 时间限制: 1 s 空间限制: 1000 KB 题目等级 : 白银 Silver 题目描述 Description 输出100以内的所有相差6的孪生素数:如, 5 11 7 13 ...
- Installing Node.js via package manager | Node.js
Installing Node.js via package manager | Node.js i386 (32-bit)
- MySQL 5.5版本解决中文乱码问题时my.ini内[mysqld]项中不能再写default-character-set=utf8
来看看如何解决乱码问题: 在mysql中默认字符集是latin1, 想要设置字符集为uft-8,可以在 my.cnf 文件中添加以下设置: [client] default-character-set ...
- DB2与Sybase/Oracle/Informix的比较
DB2是IBM的数据库产品,近年来Oracle.Sybase等数据库的大力发展曾使很多人认为DB2将逐步退出数据库市场,但几年过去了,DB2不但没有退出的迹象,反而一步步发展壮大,逐步夺回失去的市场. ...
- 转: Go -- 单例
最近在学习Golang,想着可以就以前的知识做一些串通,加上了解到go语言也是面向对象编程语言之后.在最近的开发过程中,我碰到一个问题,要用go语言实现单例模式.本着“天下知识,同根同源”(我瞎掰的~ ...
- Xcode插件管理器Alcatraz的使用
Xcode插件管理器Alcatraz的使用 下载地址 https://github.com/alcatraz/Alcatraz 下载软件包 解压以及编译 重启Xode并Load Bundle 安装插件 ...
- 纯html上下翻滚效果公告板
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...