POJ - 1836 Alignment (动态规划)
https://vjudge.net/problem/POJ-1836
题意
求最少删除的数,使序列中任意一个位置的数的某一边都是递减的。
分析
任意一个位置的数的某一边都是递减的,就是说对于数h[i],有h[1] ~ h[i]严格单增,或h[i] ~ h[n]严格单减。一开始读错题意,以为使总体递增或递减,使劲wa。。。求两个方向的LIS,用n^2解法即可。
#include<iostream>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set>
#define rep(i,e) for(int i=0;i<(e);i++)
#define rep1(i,e) for(int i=1;i<=(e);i++)
#define repx(i,x,e) for(int i=(x);i<=(e);i++)
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define mset(var,val) memset(var,val,sizeof(var))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pd(a) printf("%d\n",a)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define IOS ios::sync_with_stdio(false);cin.tie(0) using namespace std;
typedef long long ll;
template <class T>
void test(T a){cout<<a<<endl;}
template <class T,class T2>
void test(T a,T2 b){cout<<a<<" "<<b<<endl;}
template <class T,class T2,class T3>
void test(T a,T2 b,T3 c){cout<<a<<" "<<b<<" "<<c<<endl;}
template <class T>
inline bool scan_d(T &ret){
char c;int sgn;
if(c=getchar(),c==EOF) return ;
while(c!='-'&&(c<''||c>'')) c=getchar();
sgn=(c=='-')?-:;
ret=(c=='-')?:(c-'');
while(c=getchar(),c>=''&&c<='') ret = ret*+(c-'');
ret*=sgn;
return ;
}
//const int N = 1e6+10;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const ll mod = ;
int T; void testcase(){
printf("Case %d:",++T);
} const int MAXN = 5e5+ ;
const int MAXM = ;
const double eps = 1e-;
const double PI = acos(-1.0); int dp1[],dp2[];
double h[];
int main() {
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
int n;
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%lf",&h[i]); for(int i=;i<=n;i++){
dp1[i]=;
for(int j=;j<i;j++){
if(h[i]>h[j]) dp1[i]=max(dp1[i],dp1[j]+);
}
}
for(int i=n;i>=;i--){
dp2[i]=;
for(int j=n;j>i;j--){
if(h[i]>h[j]) dp2[i]=max(dp2[i],dp2[j]+);
}
}
int ans=;
for(int i=;i<=n;i++){
for(int j=i+;j<=n;j++){
ans=max(ans,dp1[i]+dp2[j]);
}
}
cout<<n-ans;
return ;
}
POJ - 1836 Alignment (动态规划)的更多相关文章
- 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
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11450 Accepted: 3647 Descriptio ...
- 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 最长递增子序列(LIS)的变形
大致题意:给出一队士兵的身高,一开始不是按身高排序的.要求最少的人出列,使原序列的士兵的身高先递增后递减. 求递增和递减不难想到递增子序列,要求最少的人出列,也就是原队列的人要最多. 1 2 3 4 ...
- POJ 1836 Alignment --LIS&LDS
题意:n个士兵站成一排,求去掉最少的人数,使剩下的这排士兵的身高形成“峰形”分布,即求前面部分的LIS加上后面部分的LDS的最大值. 做法:分别求出LIS和LDS,枚举中点,求LIS+LDS的最大值. ...
- poj 1836 LIS变形
题目链接http://poj.org/problem?id=1836 Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submiss ...
随机推荐
- vue的使用1
Vue.$set(object, key, value); <!-- Alt + C --> <input @keyup.alt.="clear"> < ...
- [转帖] BIO与NIO、AIO的区别
培训里面讲的东西 自己查了下 啥意思,,, 转帖强化一下. http://blog.csdn.net/skiof007/article/details/52873421 IO的方式通常分为几种,同步 ...
- 使用ssh tunnel 来做代理或跳板
接前文 http://www.cnblogs.com/piperck/p/6188984.html 使用ssh config配置文件来管理ssh连接 前文说了如何配置自己的ssh config 来方 ...
- awk、sed、grep三大shell文本处理工具之sed的应用
sed 流编辑器 对文本中的行,逐行处理 非交互式的编辑器 是一个编辑器 1.工作流程 1)将文件的第一行读入到自己的缓存空间(模式空间--pattern space),删除掉换行符 2)匹配,看一下 ...
- JIRA & GitHub
JIRA & GitHub https://confluence.atlassian.com/adminjiracloud/connect-jira-cloud-to-github-81418 ...
- schema举例一
schema举例一: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs=& ...
- BZOJ5294 [BJOI2018] 二进制 【线段树】
BJOI的题目感觉有点难写 题目分析: 首先推一波结论.接下来的一切都在模3意义下 现在我们将二进制位重组,不难发现的是2^0≡1,2^1≡2,2^2≡1,2^3≡2....所以我们考虑这样的式子 2 ...
- MT【236】必要性探路
$\dfrac{lnx}{x+1}+\dfrac{1}{x}>\dfrac{lnx}{x-1}+\dfrac{k}{x}$对于任意$x>0$成立,求$k$的范围. 解答:由题意,对任意$x ...
- MT【32】内外圆(Apollonius Circle)的几何证明
另一方面,如果 M 满足(1)式,那么M必然在以PQ为直径的圆上.事实上当M为P或者Q时,这是显然的.当M异于P,Q时,由$\frac{|MB|}{|MC|}=\frac{|PB|}{|PC|}=\l ...
- 自学Linux Shell16.3-函数递归+创建库
点击返回 自学Linux命令行与Shell脚本之路 16.3-函数递归+创建库 1. 函数递归 递归调用函数是指函数调用自身进行求解. 通常,递归函数有基值,函数最终递推到达该值. 许多高级数学算法使 ...