poj 1836
来源:互联网 发布:曾经的网络流行语 编辑:程序博客网 时间:2024/05/17 03:09
传送门http://poj.org/problem?id=1836
LIS的变形
两次LIS再相加取最大
//题目大意是给出一队士兵,要从中选一些人出来,使剩下的队列满足//a1 < a2 < a3 ... < a(i ) <=> a(i+1) > a(i+2) > .. a(n-1) > a(n)#include<iostream>#include<cstdio>#define maxn 1005using namespace std;double a[maxn];int l[maxn]={0},r[maxn]={0};int main(){ int n; cin>>n; for(int i=1;i<=n;i++) scanf("%lf",&a[i]); l[1]=1; for(int i=2;i<=n;i++) { l[i]=1; for(int j=1;j<i;j++) if(a[j]<a[i]&&l[j]>=l[i]) l[i]=l[j]+1; } r[n]=1; for(int i=n-1;i>=1;i--) { r[i]=1; for(int j=n;j>i;j--) { if(a[j]<a[i]&&r[j]>=r[i]) r[i]=r[j]+1; } } int max=0; for(int i=1;i<=n-1;i++)//不用到n 因为r[n]=1 用max=r[n]+l[n-1]相加代替了 for(int j=i+1;j<=n;j++)//中间的人可以抽走 不必连着 { if(l[i]+r[j]>max) max=l[i]+r[j]; } cout<<n-max<<endl;}
- 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
- ORACLE 定时作业DBMS_JOB的编写
- 如果你准备在2013奋斗,请好好研究这些铁律
- VPS
- Flex TextArea组件简单应用:文字链接,图片显示,字体设置
- naxsi 参数详解
- poj 1836
- ORACLE语句
- Android 亲测源码分享
- openstack 监控 - 整合nagios 调研总结
- 一个关于ACE Service Configurator的小例子
- iOS单例模式的实现
- 软件随想录(local.joelonsoftware.com/wiki)-2001年05月05日 这个国家的狗做什么工作? - What Is the Work of Dogs in this Cou
- 产品经理们最需要理解的3种方式
- NSBundle的使用