题目链接

分析:

从左向右求一遍LIS,再从右向左求一遍LIS,最后一综合,就OK了。

注意:

有一种特殊情况(详见discuss):

8
3 4 5 1 2 5 4 3
答案是:2

AC代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue> using namespace std; const int maxn = + ;
const double INF = 1e100; double a[maxn];
int d1[maxn], d2[maxn];\ int main() {
int n;
// freopen("my.txt", "r", stdin); while(cin>>n) {
for(int i=; i<n; i++) cin>>a[i]; d1[] = ;
for(int i=; i<n; i++) {
int m = ;
for(int j=; j<i; j++) {
if(a[j] < a[i] && m < d1[j]) m = d1[j];
}
d1[i] = m+;
} d2[n-] = ;
for(int i=n-; i>=; i--) {
int m = ;
for(int j=n-; j>i; j--) {
if(a[j] < a[i] && m < d2[j]) m = d2[j];
}
d2[i] = m+;
} int ans = ;
for(int i=; i<n; i++) {
for(int j=i+; j<n; j++) {
ans = max(ans, d1[i]+d2[j]);
}
}
printf("%d\n", n-ans);
} return ;
}

加个二分写法,在《训练指南》上学的二分写法,解题思想一样,写法不一样而已。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <algorithm> using namespace std; const int maxn = + ;
const double INF = 1e100; double a[maxn];
int d1[maxn], d2[maxn];
double G[maxn]; int main() {
int n;
//freopen("my.txt", "r", stdin);
while(cin>>n) {
for(int i=; i<n; i++) cin>>a[i]; for(int i=; i<=n; i++) G[i] = INF;
for(int i=; i<n; i++) {
int k = lower_bound(G+, G+n+, a[i]) - G;
G[k] = a[i];
d1[i] = k;
} for(int i=; i<=n; i++) G[i] = INF;
for(int i=n-; i>=; i--) {
int k = lower_bound(G+, G+n+, a[i]) - G;
G[k] = a[i];
d2[i] = k;
} int ans = ;
for(int i=; i<n; i++) {
for(int j=i+; j<n; j++) {
ans = max(ans, d1[i]+d2[j]);
}
}
printf("%d\n", n-ans);
} return ;
}

最新文章

  1. Events基本概念----Beginning Visual C#
  2. 如何获得PRINCE2认证
  3. linux-shell编程笔记01
  4. centos6.5编译安装git
  5. 如何连接git bash和git hub
  6. 33条C#、.Net经典面试题目及答案
  7. Python调用Webservice、访问网页
  8. ExtJS4.2学习(13)基于表格的扩展插件---rowEditing
  9. [转]详述DHCP服务器的三种IP分配方式
  10. Asp.net MVC + EF6.0 经常出现的问题
  11. Bean-Query 一个把对象转换为Map的Java工具库
  12. HDU 5543 Pick The Sticks
  13. Spring Boot 2.0(四):使用 Docker 部署 Spring Boot
  14. v4v7升级到androidx过程
  15. idea启动tomcat 找不到 类,或者报Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
  16. [Sw] 使用 Swoole Server task/协程 处理大数据量异步任务时注意
  17. C#中equal与==的区别
  18. selenium case报错重新执行
  19. 干货|技术小白如何在45分钟内发行通证(TOKEN)并上线交易(附流程代码
  20. linux basic test

热门文章

  1. TCP/IP协议原理与应用笔记10:TCP/IP协议族
  2. 500 OOPS: vsftpd: refusing to run with writable root inside chroot()解决方法
  3. UWP app HelloWorld 的创建
  4. frontpage 正则 查找与替换
  5. canvas --&gt; getImageData()
  6. javascript实现Map
  7. cenos6.5 64位下PHP远程连接sql server2008成功案例
  8. 抓取锁的sql语句-第一次修改
  9. ORACLE调度之基于事件的调度(二)【weber出品】
  10. &lt;q&gt;标签,短文本引用