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 ...
随机推荐
- yum安装pip,pip安装compose
#centos7 yum -y install epel-release yum -y install python-pip pip install --upgrade pip pip install ...
- CentOS7.5搭建Solr7.4.0单机服务
一.Solr安装环境 1.官方参考文档 Solr教程参考指南:http://lucene.apache.org/solr/guide/7_4/solr-tutorial.html 2.Solr运行环境 ...
- Linux下的反调试技术
Linux下的反调试技术 2014年01月30日 ⁄ 综合 ⁄ 共 2669字 ⁄ 字号 小 中 大 ⁄ 评论关闭 转自 http://wangcong.org/blog/archives/310 ...
- Python实现简单HTTP服务器(一)
一.返回固定内容 # coding:utf-8 import socket from multiprocessing import Process def handle_client(client_s ...
- -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
本人使用mac系统,命令行工具使用的iterm2,登录自己的云主机的时候 每次都要提示如下错误 -bash: warning: setlocale: LC_CTYPE: cannot change l ...
- How Many Answers Are Wrong----hdu3038(并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 题意:数组第 a 个元素到第 b 个元素之间的和为sum: 求有几句话是假的,如果与前面的话有冲 ...
- router-link传参 query方式
router.js内的路由配置 { path: '/CreateProgress', name: 'CreateProgress', component:CreateProgress } 传参(q ...
- qt——for循环里创建widget
在for循环里创建 widget,比如test类 不能使用 test t; 而要使用 test t = new test(): for (i=0;i<=3;i++) { QPushButton* ...
- 【HTML5】初识HTML5
HTML5 简介 HTML5是HTML最新的修订版本,2014年10月由万维网联盟(W3C)完成标准制定. HTML5的设计目的是为了在移动设备上支持多媒体. HTML5 简单易学. HTML5 是下 ...
- sql server字符串中怎么添加换行?
换行/回车,可以使用CHAR函数处理,比如: 1 insert into tbtest (text) values ('abc' + char(13)+char(10) + 'def') 主要还是要看 ...