POJ 1836
刚开始二分写错了 wa了很久 这个二分 的好好想想
#include <iostream>
#include<cstdio>
#include<string.h>
#include<cmath>
using namespace std;
const double eps=1e-10;
double dp[2005],L[2005],R[2005];
int n;
int BIN(int len,double x)
{
int left=0,right=len-1,mid;
while(left<right)
{
mid=(left+right)/2;
if(x>L[mid])left=mid+1;
else right=mid;
}
return left;
}
int work(int li,int ri)
{
int i,gh=0,pos;
L[0]=dp[0];
int len=1,sum=0,KH=0;
for(i=n-1;i>=ri;i--)
R[KH++]=dp[i];
for(i=1;i<li+1;i++)
{
if(dp[i]>L[len-1])
{
L[len++]=dp[i];
}
else
{
pos=BIN(len,dp[i]);
L[pos] =dp[i];
}
}
sum=li+1-len;
gh=0;
len=1;
L[0]=R[0];
for( i=1;i<KH;i++)
{
if(R[i]>L[len-1] )
{
L[len++]=R[i];
}
else
{
pos=BIN(len,R[i]);
L[pos] =R[i];
}
}
sum+=KH-len;
return sum;
}
int main()
{
int maxn,kk,i;
while(scanf("%d",&n)==1)
{
maxn=1000000;
for(i=0;i<n;i++)
scanf("%lf",&dp[i]);
for( i=0;i<n-1;i++)
if((kk=work(i,i+1))<maxn)maxn=kk;
printf("%d\n",maxn);
}
return 0;
}
POJ 1836的更多相关文章
- 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 LIS变形
题目链接http://poj.org/problem?id=1836 Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submiss ...
- POJ 1836 Alignment 最长递增子序列(LIS)的变形
大致题意:给出一队士兵的身高,一开始不是按身高排序的.要求最少的人出列,使原序列的士兵的身高先递增后递减. 求递增和递减不难想到递增子序列,要求最少的人出列,也就是原队列的人要最多. 1 2 3 4 ...
- POJ 1836 Alignment --LIS&LDS
题意:n个士兵站成一排,求去掉最少的人数,使剩下的这排士兵的身高形成“峰形”分布,即求前面部分的LIS加上后面部分的LDS的最大值. 做法:分别求出LIS和LDS,枚举中点,求LIS+LDS的最大值. ...
- POJ 1836 Alignment
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11450 Accepted: 3647 Descriptio ...
- POJ - 1836 Alignment (动态规划)
https://vjudge.net/problem/POJ-1836 题意 求最少删除的数,使序列中任意一个位置的数的某一边都是递减的. 分析 任意一个位置的数的某一边都是递减的,就是说对于数h[i ...
- POJ 1836 Alignment (双向DP)
Alignment Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10804 Accepted: 3464 Descri ...
随机推荐
- (TOJ 4413)IP address
描述 To give you an IP address, it may be dotted decimal IP address, it may be 32-bit binary IP addres ...
- for,for-each,for-in,for-of,map的比较
参考: 全面解析JavaScript里的循环方法之forEach,for-in,for-of Iterator 和 for...of 循环 JavaScript Array 对象 常规for for循 ...
- iOS 面试题整理(带答案)二
第一篇面试题整理: http://www.cocoachina.com/bbs/read.php?tid-459620.html 本篇面试题同样:如答案有问题,欢迎指正! 1.回答person的ret ...
- oracle的日期相减
oracle的日期相减 : 两个date类型的 日期相减,得到的是天数,可能是带小数点的.如下:
- 使用不同模板引擎beetl、FreeMarker、Velocity动态解析sql的方法
1. String sql = null;if(null == renderType || renderType.equals(ConstantRender.sql_renderType_beetl) ...
- 单引号、双引号、int和char
首先说一下C语言中用单引号和双引号的不同(一直搞不清楚): 单引号代表的是一个整数,而这个整数的值是编译器所采用的字符集中的字符序列对应的值.所以一般'A'和ASCII中的65意义相同.对于双引号定义 ...
- Mapreduce 原理及程序分析
1.MapReduce(Map+Reduce) 提出一个问题: 目标:你想数出一摞牌中有多少张黑桃. 直观方式:一张一张检查并且数出有多少张是黑桃数目 MapReduce方法则是: 给在座的所有玩家中 ...
- 老师的blog整理
python基础部分: 宝哥blog: https://www.cnblogs.com/guobaoyuan/ 开哥blog: https://home.cnblogs.com/u/Neeo 女神笔记 ...
- Thymeleaf模板引擎的初步使用
在springboot中,推荐使用的模板引擎是Thymeleaf模板引擎,它提供了完美的Spring MVC的支持.下面就简单的介绍一下Thymeleaf模板引擎的使用. 在controller层中, ...
- LoadRunner-参数化(连接数据库)
多用户并发测试,用户信息来自数据库,对脚本中accounts值替换为参数后,打开参数列表. 1.点击 Data Wizard...:选择Specify SQL statement manu: 2.点击 ...