poj 1836 Alignment(dp)
题目:http://poj.org/problem?id=1836
题意:最长上升子序列问题, 站队,求踢出最少的人数后,使得队列里的人都能看到 左边的无穷远处 或者 右边的无穷远处。
代码O(n^2):
#include<iostream>
#include<cstring>
using namespace std; int main()
{
int n,i,j,d1[],d2[],mx;
double a[];
cin>>n;
for(i=; i<=n; i++)
cin>>a[i];
d1[]=;
for(i=; i<=n; i++)
{
mx=;
for(j=; j<i; j++)
if(a[i]-a[j]>&&d1[j]>=mx)
{
mx=d1[j]+;
}
d1[i]=mx;
}
d2[n]=;
for(i=n-; i>=; i--)
{
mx=;
for(j=n; j>i; j--)
if(a[i]-a[j]>&&d2[j]>=mx)
{
mx=d2[j]+;
}
d2[i]=mx;
}
mx=-;
for(i=; i<=n; i++)
for(j=i+; j<=n; j++)
if(d1[i]+d2[j]>mx)
mx=d1[i]+d2[j];
cout<<n-mx<<endl;
return ;
}
poj 1836 Alignment(dp)的更多相关文章
- 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)
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 ...
- POJ 1836 Alignment 最长递增子序列(LIS)的变形
大致题意:给出一队士兵的身高,一开始不是按身高排序的.要求最少的人出列,使原序列的士兵的身高先递增后递减. 求递增和递减不难想到递增子序列,要求最少的人出列,也就是原队列的人要最多. 1 2 3 4 ...
- POJ 1836 Alignment --LIS&LDS
题意:n个士兵站成一排,求去掉最少的人数,使剩下的这排士兵的身高形成“峰形”分布,即求前面部分的LIS加上后面部分的LDS的最大值. 做法:分别求出LIS和LDS,枚举中点,求LIS+LDS的最大值. ...
- POJ - 1836 Alignment (动态规划)
https://vjudge.net/problem/POJ-1836 题意 求最少删除的数,使序列中任意一个位置的数的某一边都是递减的. 分析 任意一个位置的数的某一边都是递减的,就是说对于数h[i ...
- poj 1836 LIS变形
题目链接http://poj.org/problem?id=1836 Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submiss ...
随机推荐
- 从 Typecho 自定义字段的调用代码看去
千呼万唤,Typecho 的"自定义字段"功能终于在 0.9 中出来了.然而,多数人还蒙在这样一个鼓里--该怎么在模板调用已经设置好的自定义字段呢?让我们从这里开始说下去: Typ ...
- 简单3D翻转
1.先上图~~~ 2.代码 html部分 <body> <div id="my3d"> <div id="box"> < ...
- Demo学习: Cookies Demo
Cookies Demo 浏览器Cookies的读写,最常用的就是记录用户的登录信息,在项目里做登录界面时也用到了Cookies功能. procedure TMainForm.UniButton2Cl ...
- 1078. Hashing (25)
时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The task of this problem is simp ...
- (转)Qt Model/View 学习笔记 (四)——创建新的Models
创建新的Models 介绍 model/view组件之间功能的分离,允许创建model利用现成的views.这也可以使用标准的功能 图形用户接口组件像QListView,QTableView和QTre ...
- Arcgis投影变换后图像变深的问题
首先投影时,重采样方式选择nearest最邻近采样法,不改变投影后图像的DN值。 然后双击投影后图像,在符号系统中选择RGB——拉伸类型改为:无(默认是标准差拉伸)
- easy ui 异步上传文件,跨域
easy ui 跨域上传文件,代码如下: 1.html代码:(这段代码是个win窗体,我在点击上传图片按钮然后弹出一个上传图片的窗体,选择图片再进行上传,这样在form提交时,提交的参数会少一点.) ...
- Xcode文档下载与安装路径
https://developer.apple.com/library/downloads/docset-index.dvtdownloadableindex ~/Library/Developer/ ...
- 【HDU2222】Keywords Search
Problem DescriptionIn the modern time, Search engine came into the life of everybody like Google, Ba ...
- c#3位一分(money)
NumberFormatInfo num = new NumberFormatInfo(); num.NumberDecimalDigits = 2; string ...