博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1836, Alignment
阅读量:5972 次
发布时间:2019-06-19

本文共 2698 字,大约阅读时间需要 8 分钟。

Time Limit: 1000MS  Memory Limit: 30000K

Total Submissions: 3283  Accepted: 963

Description
In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are aligned in a straight line in front of the captain. The captain is not satisfied with the way his soldiers are aligned; 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

On the first line of the input is written the number of the soldiers n. On the second line is written a series of n floating numbers with at most 5 digits precision and separated by a space character. The k-th number from 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

The only line of output will contain the number of the soldiers who have to get out of the line.

 

Sample Input

8
1.86 1.86 1.30621 2 1.4 1 1.97 2.2

 

Sample Output

4

 

Source

Romania OI 2002


//
 POJ1836.cpp : Defines the entry point for the console application.
//
#include 
<
iostream
>
#include 
<
algorithm
>
using
 
namespace
 std;
int
 main(
int
 argc, 
char
*
 argv[])
{
    
int
 N;
    scanf(
"
%d
"
&
N);
    
double
 ln[
1000
];
    
for
 (
int
 i 
=
 
0
; i 
<
 N; 
++
i) scanf(
"
%lf
"
&
ln[i]);
    
int
 DP[
2
][
1000
];
    fill(
&
DP[
0
][
0
],
&
DP[
0
][N],
1
);
    
for
 (
int
 j 
=
 
1
; j 
<
 N; 
++
j)
    {
        
for
 (
int
 k 
=
 
0
; k 
<
 j; 
++
k)
      
if
 (ln[k] 
<
 ln[j] 
&&
 DP[
0
][k] 
+
 
1
 
>
 DP[
0
][j]) DP[
0
][j] 
=
 DP[
0
][k] 
+
 
1
;
    }
    fill(
&
DP[
1
][
0
],
&
DP[
1
][N],
1
);
    
for
 (
int
 j 
=
 N 
-
 
1
; j 
>=
 
0
--
j)
    {
        
for
 (
int
 k 
=
 N 
-
 
1
; k 
>
 j; 
--
k)
     
if
 (ln[k] 
<
 ln[j] 
&&
 DP[
1
][k] 
+
 
1
 
>
 DP[
1
][j]) DP[
1
][j] 
=
 DP[
1
][k] 
+
 
1
;
    }
    
for
 (
int
 j 
=
 
1
; j 
<
 N; 
++
j) DP[
0
][j] 
=
 max(DP[
0
][j
-
1
],DP[
0
][j]);
    
for
 (
int
 j 
=
 N 
-
 
2
; j 
>=
 
0
--
j) DP[
1
][j] 
=
 max(DP[
1
][j
+
1
],DP[
1
][j]);
    
int
 mppl 
=
 N 
-
 max(DP[
0
][N
-
1
], DP[
1
][
0
]);
    
for
 (
int
 i 
=
 
1
; i 
<
 N 
-
 
1
++
i)
        mppl 
=
 min(mppl, N 
-
 DP[
0
][i 
-
 
1
-
 DP[
1
][i]);
    cout 
<<
 mppl 
<<
 endl;
    
return
 
0
;
}

转载于:https://www.cnblogs.com/asuran/archive/2009/10/13/1582292.html

你可能感兴趣的文章
交互设计[3]--点石成金
查看>>
SCCM TP4部署Office2013
查看>>
SVN: bdb: BDB1538 Program version 5.3 doesn't match environment version 4.7
查看>>
jsp内置对象作业3-application用户注册
查看>>
redis主从配置<转>
查看>>
bootloader功能介绍/时钟初始化设置/串口工作原理/内存工作原理/NandFlash工作原理...
查看>>
Web应用工作原理、动态网页技术
查看>>
EXCEL工作表保护密码破解 宏撤销保护图文教程
查看>>
Catalan数(卡特兰数)
查看>>
python 数据库中文乱码 Excel
查看>>
利用console控制台调试php代码
查看>>
递归算法,如何把list中父子类对象递归成树
查看>>
hdu 1050 (preinitilization or postcleansing, std::fill) ...
查看>>
Linux vmstat命令实战详解
查看>>
我的友情链接
查看>>
替换k个字符后最长重复子串
查看>>
讲解sed用法入门帖子
查看>>
Java异常学习心得
查看>>
Scala学习之类和属性篇(一):定义类的主构造方法
查看>>
使用阿里云CentOS安装LAMP时,安装PHP扩展需要注意的事情
查看>>