// File Name: 3670.cpp
// Author: Missa_Chen
// Created Time: 2013年07月08日 星期一 21时15分34秒 #include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <cstdlib>
#include <vector>
#include <time.h> using namespace std; #define LL long long
const int inf = 0x3f3f3f3f;
const int maxn = 3e4 + ;
int a[maxn], dp[maxn], D[maxn], len, n;
//dp[i]表示以第i个元素为子序列最后一个元素的LIS长度。
//D[len]表示上升子序列长度为len的最后一个元素。
int LIS()
{
len = ;
memset(dp, , sizeof(dp));
memset(D, , sizeof(D));
int ret = ;
for (int i = ; i <= n; ++i)
{
if (a[i] >= D[len])
{
dp[i] = len + ;
D[++len] = a[i];
}
else
{
int low = , high = len, tmp = ;
while (low <= high)
{
int mid = (low + high) >> ;
if (D[mid] <= a[i])
{
tmp = mid;
low = mid + ;
}
else
high = mid - ;
}
dp[i] = tmp + ;
D[tmp + ] = a[i];
}
ret = max(ret, dp[i]);
}
return ret;
}
int main()
{
while (~scanf("%d",&n))
{
for (int i = ; i <= n; ++i)
scanf("%d", &a[i]);
int ans = LIS();
reverse(a + , a + n + );
ans = max(ans, LIS());
printf("%d\n", n - ans);
}
return ;
}

最新文章

  1. git知识点整理
  2. python selenium 操作chrome
  3. 和为S的连续正数序列
  4. Shell基础整理
  5. R语言将List转为矩阵do.call
  6. DIY Ruby CPU 分析——Part I
  7. VMware ESXI4.1 常用命令
  8. SimpleWiFi模块评估板
  9. C#设置richtextbox某一段文本颜色
  10. arclistsg文档独立模型标签
  11. sed的N;P用法
  12. 迅为iTOP-4418/6818开发板-驱动-实现GPIO扩展
  13. php 文件系统函数及目录函数
  14. java 实现加密算法(在网上看的,保存)
  15. Livepeer中文白皮书(翻译)
  16. gohost -- go 开发的命令行hosts配置管理工具
  17. Orleans学习总结(二)--创建工程
  18. 【树】Path Sum II(递归)
  19. Xilinx Altera FPGA中的逻辑资源(Slices VS LE)比较
  20. 使用pandas把mysql的数据导入MongoDB。

热门文章

  1. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-如何配置虚拟轴 TC2
  2. Joomla详细安装图文教程
  3. Android Exception 15(关于使用RecyclerView的异常)
  4. HDU 4632 Palindrome subsequence(区间dp)
  5. Visual studio C++ MFC之点击按钮(菜单栏)生成新窗口
  6. mysql的innodb数据库引擎详解
  7. HDU 4287 Intelligent IME(map运用)
  8. SqlServer+Topshelf+Quartznet做集群,定时任务分布式处理
  9. HTTP请求报文属性详解
  10. MySQL学习总结(三)索引