poj 1836
来源:互联网 发布:担保公司业务软件 编辑:程序博客网 时间:2024/06/06 14:08
求两遍LIS,枚举每个点
代码如下
补充一下,l[i],r[i]也可以直接用lower_bound(dp,dp+n,3.0)-dp代替
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;int main(){double h[1005],dp[1005];int l[1005],r[1005];int n;scanf("%d",&n);for(int i=0;i<n;i++)scanf("%lf",&h[i]);int cnt=1;for(int i=0;i<n;i++)dp[i]=3.0;for(int i=0;i<n;i++){int p=lower_bound(dp,dp+n,h[i])-dp;cnt=max(cnt,p+1);dp[p]=h[i];l[i]=cnt;}cnt=1;for(int i=0;i<n;i++)dp[i]=3.0;for(int i=n-1;i>=0;i--){int p=lower_bound(dp,dp+n,h[i])-dp;cnt=max(cnt,p+1); dp[p]=h[i];r[i]=cnt;}int ans=max(l[n-1],r[0]);for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)ans=max(ans,l[i]+r[j]);printf("%d\n",n-ans); }
阅读全文
0 0
- POJ 1836
- POJ 1836
- poj 1836
- poj.1836
- poj-1836
- poj 1836
- poj 1836
- poj 1836
- poj 1836
- POJ 1836 Alignment
- POJ 1836 Alignment
- poj 1836 Alignment
- Poj 1836 Alignment
- poj 1836 Alignment
- POJ 1836-Alignment
- POJ 1836(双向LIS)
- poj 1836 Alignment
- POJ 1836 Alignment
- Linux开发工具(gcc gdb make shell)——GCC中-I -L -l区别
- Visual Assist实现*.h和*.cpp的函数声明和定义的同步。
- Leetcode#35: Search Insert Position
- 打印倒三角形*,包含最后一颗*
- 数字信号处理——图像篇
- poj 1836
- spark源码分析之DAGScheduler提交作业(job)过程、stage阶段说明
- MCU调试gprs模块遇到些问题总结如下
- HashSet类
- java class 零星知识点集合
- 分分钟getXML解析之DOM解析。
- Linux开发工具(gcc gdb make shell)——GCC 三级优化
- 计算机图形学的数学基础
- CCF 201609-2 火车购票