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 ...
随机推荐
- GitLab添加ssh-key,操作无需每次输入账号密码
git config --global credential.helper store 然后操作pull/push 会让输入用户名密码,第一次输入进去.下次再操作pull/push时就不需要输入用户名 ...
- 转载 linux常用的监控命令工具
工具 简单介绍top 查看进程活动状态以及一些系统状况vmstat 查看系统状态.硬件和系统信息等iostat 查看CPU 负载,硬盘状况sar 综合工具,查看系统状况mpstat 查看多处理器状况n ...
- zlib 简单封装
下列代码用于压缩和解压字符串,使用标准库string.实现了对zlib的简单封装. #pragma once #include <boost/noncopyable.hpp> #inclu ...
- WINFORM 多条件动态查询 通用代码的设计与实现
经常碰到多条件联合查询的问题,以前的习惯认为很简单总会从头开始设计布局代码,往往一个查询面要费上老半天的功夫,而效果也不咋地. 前段时间做了个相对通用的多条件动态查询面,复用起来还是挺方便的, ...
- BZOJ3175[Tjoi2013]攻击装置——二分图最大独立集
题目描述 给定一个01矩阵,其中你可以在0的位置放置攻击装置.每一个攻击装置(x,y)都可以按照“日”字攻击其周围的 8个位置(x-1,y-2),(x-2,y-1),(x+1,y-2),(x+2,y- ...
- BZOJ3625 [Codeforces Round #250]小朋友和二叉树(生成函数+多项式开根)
设f(n)为权值为n的神犇二叉树个数.考虑如何递推求这个东西. 套路地枚举根节点的左右子树.则f(n)=Σf(i)f(n-i-cj),cj即根的权值.卷积的形式,cj也可以通过卷上一个多项式枚举.可以 ...
- hdu 3727 Jewel (可持久化线段树+bit)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=3727 题意: 对一段序列进行四种操作: Insert x :在序列尾部插入一个x: Query_1 s ...
- JPQL设置自增长、只读、文本类型等的注解
JAVA中使用JPQL 一种设置id自动生成,自增长的方法 private long id; @Id @GeneratedValue(generator="_native") @G ...
- 【POI每日题解 #8】DYN-Dynamite
你问蒟蒻为什么一天写两篇每日题解? 难道每日坚果你不能一天吃两包吗? 题目链接 哇…这道题第一反应就是二分答案[太明显了 枚举答案 就那个“关键节点到这些点中距离的最小值的最大值”[蒟蒻读了好几遍…… ...
- 工具函数判断data为整型字符串
/** * 如果data是整型字符串,则转为整型,否则原样返回 * @param {*} data 整型字符串 */ export const stringToInt = (data) => { ...