poj 1836 Alignment
来源:互联网 发布:编程培训班学费 编辑:程序博客网 时间:2024/06/05 17:32
Alignment
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 15646 Accepted: 5091
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.
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]
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
81.86 1.86 1.30621 2 1.4 1 1.97 2.2
Sample Output
4
Source
Romania OI 2002
这道题意思是让最少的人出列,使得队伍中的每个人都至少能看见一边的底线(就是说能看见最左边或最右边)
用两次LIS,然后枚举分界点就可以了。
#include<iostream>#include<cstring>#include<string>#include<cstdio>#include<algorithm>using namespace std;double height[1001];int dp[1001];int dp2[1001];int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;++i) { scanf("%lf",&height[i]); } for(int i=1;i<=n;++i) { dp[i]=1; for(int j=i-1;j>=1;--j) { if(height[i]>height[j]) { dp[i]=max(dp[i],dp[j]+1); } } } for(int i=n;i>=1;--i) { dp2[i]=1; for(int j=i+1;j<=n;++j) { if(height[i]>height[j]) { dp2[i]=max(dp2[i],dp2[j]+1); } } } int tmp=0; for(int i=1;i<n;++i) { for(int j=i+1;j<=n;++j) { if(dp[i]+dp2[j]>tmp) { tmp=dp[i]+dp2[j]; } } } printf("%d\n",n-tmp); return 0;}
0 0
- POJ 1836 Alignment
- POJ 1836 Alignment
- poj 1836 Alignment
- Poj 1836 Alignment
- poj 1836 Alignment
- POJ 1836-Alignment
- poj 1836 Alignment
- POJ 1836 Alignment
- POJ 1836 Alignment
- POJ 1836 Alignment
- POJ 1836 Alignment
- POJ 1836 Alignment
- POJ 1836 Alignment
- poj 1836 Alignment
- poj 1836 Alignment
- poj 1836 Alignment
- POJ - 1836 Alignment
- poj 1836 Alignment
- ISCC2016 BASE 第二题好长的字符串
- java多线程与内存可见性
- Android签名与风险分析
- 山东省第七届ACM省赛------Fibonacci
- js弹出框、对话框、提示框、弹窗总结
- poj 1836 Alignment
- ASP.NET使用一般处理程序生成验证码
- 剑指offer面试题4 替换空格
- JAVA之代码混淆proguard
- Ajax+Servlet
- C#设计模式—建造者模式
- SQL技巧
- HDU 1561 The more, The Better(树形DP)
- apache+mysql+php实现最大负载的方法