poj1836--Alignment(dp,最长上升子序列变形)
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 13319 | Accepted: 4282 |
Description
it is true that the soldiers are aligned 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
this line represents the height of 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
Source
题目要求:给出n个人排成一排。踢出一些人。让每一个人都能看到最左端,或最后端,最小的踢出人数是?
计算出正序和倒序的最长上升子序列,然后统计:有两种可能。一种是当中一个人是中间。那个人的身高最高。还有事两个人的身高同样。这两个人位置在中间,统计出最长的可能出现的队伍长度,计算出最小的踢出人数
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int dp1[1200] , dp2[1200] ;
double h[1200] ;
int main()
{
int i , j , n , min1 ;
while(scanf("%d", &n)!=EOF)
{
min1 = 1200 ;
h[0] = 0 ; h[n+1] = 0 ;
for(i = 1 ; i <= n ; i++)
scanf("%lf", &h[i]);
memset(dp1,0,sizeof(dp1));
for(i = 1 ; i <= n ; i++)
{
for(j = 0 ; j < i ; j++)
if( h[j] < h[i] && dp1[j]+1 > dp1[i] )
dp1[i] = dp1[j]+1 ;
}
memset(dp2,0,sizeof(dp2));
for(i = n ; i >= 1 ; i--)
{
for(j = n+1 ; j > i ; j--)
if( h[j] < h[i] && dp2[j]+1 > dp2[i] )
dp2[i] = dp2[j]+1 ;
}
for(i = 1 ; i <= n ; i++)
{
for(j = i ; j <= n ; j++)
{
if(i == j)
min1 = min(min1,n-(dp1[i]+dp2[j]-1) );
else
min1 = min(min1, n-( dp1[i]+dp2[j] ) );
}
}
printf("%d\n", min1);
}
}
poj1836--Alignment(dp,最长上升子序列变形)的更多相关文章
- 洛谷 P1020 导弹拦截(dp+最长上升子序列变形)
传送门:Problem 1020 https://www.cnblogs.com/violet-acmer/p/9852294.html 讲解此题前,先谈谈何为最长上升子序列,以及求法: 一.相关概念 ...
- poj1159--Palindrome(dp:最长公共子序列变形 + 滚动数组)
Palindrome Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 53414 Accepted: 18449 Desc ...
- uva 10131 Is Bigger Smarter ? (简单dp 最长上升子序列变形 路径输出)
题目链接 题意:有好多行,每行两个数字,代表大象的体重和智商,求大象体重越来越大,智商越来越低的最长序列,并输出. 思路:先排一下序,再按照最长上升子序列计算就行. 还有注意输入, 刚开始我是这样输入 ...
- hdu 1025 dp 最长上升子序列
//Accepted 4372 KB 140 ms //dp 最长上升子序列 nlogn #include <cstdio> #include <cstring> #inclu ...
- DP——最长上升子序列(LIS)
DP——最长上升子序列(LIS) 基本定义: 一个序列中最长的单调递增的子序列,字符子序列指的是字符串中不一定连续但先后顺序一致的n个字符,即可以去掉字符串中的部分字符,但不可改变其前后顺序. LIS ...
- ACM: 强化训练-Beautiful People-最长递增子序列变形-DP
199. Beautiful People time limit per test: 0.25 sec. memory limit per test: 65536 KB input: standard ...
- hdu 1080 dp(最长公共子序列变形)
题意: 输入俩个字符串,怎样变换使其所有字符对和最大.(字符只有'A','C','G','T','-') 其中每对字符对应的值如下: 怎样配使和最大呢. 比如: A G T G A T G - G ...
- hdu1503 最长公共子序列变形
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1503 题意:给出两个字符串 要求输出包含两个字符串的所有字母的最短序列.注意输出的顺序不能 ...
- HOJ Recoup Traveling Expenses(最长递减子序列变形)
A person wants to travel around some places. The welfare in his company can cover some of the airfar ...
随机推荐
- QUrl不同版本之间的坑
在项目中使用了native application + html的方式构建界面. 之前在4.8.4用QUrl直接加载相对路径一点问题都没有.但是切换到5.1编译之后却发现本地的html文件全部没有加载 ...
- HDU5090模拟,hash
/* HDU 5090 算是一道简单模拟题.但当中有非常深的hash思想 这是本人的第一道hash题 更是本人的第一道纸质代码不带编译不带执行提交AC的题 值得纪念 废话讲这么多之后,讲述题中思想 因 ...
- Jquery文本框小例(必填框)
<script src="../JavaScript/jquery-2.0.2.min.js"></script> <script type=&quo ...
- LINQ to SQL的一些简单用法
static void Main(string[] args) { var personList = new List<Person> { new Person() { PersonID= ...
- 实现长按删除QListWidget的Item
原地址:http://blog.sina.com.cn/s/blog_5c70dfc80100r99u.html 要想长按删除QListWidget的Item,必须重写鼠标事件,所以需要继承QList ...
- C++ 观察者模式样例
C++ 观察者模式样例 #include <iostream> #include <set> #include <string> using namespace s ...
- <转载>CSS解决图片过大撑破DIV的方法
DIV+CSS网页内容中如果插入大于DIV层宽度显示,过大的图片将会撑破网页宽度显示从而网页严重变形,您是否遇到过?这里DIVCSS5给大家介绍几种解决图片撑破撑开网页DIV层方法. 图片撑破宽度解决 ...
- shell基础(转)
shell基础1:文件安全与权限 http://bbs.chinaunix.net/forum/viewtopic.php?t=434579&highlight=wingger 附:Linux ...
- HDOJ 2442 -bricks 状态压缩DP 一直TLE.打表过的..
有5个砖块..加上一个空着不放..那么有6种状态..所以很明显的可以用6进制的状态DP... 不过这么做..我觉得我已经能优化的都优化了...还是超时..一看数据范围是100*6..打表先AC了.. ...
- 判断Webbrowser是否加载完成
var Form1: TForm1; glpDisp: IDispatch = nil; implementation {$R *.dfm} procedure TForm1.EmbeddedWB1D ...