博客
关于我
sdnu1172.Queue(双向LIS)
阅读量:286 次
发布时间:2019-03-01

本文共 1532 字,大约阅读时间需要 5 分钟。

Description

    On the PE,the teacher wants to choose some of n students to play games. Teacher asks n students stand in a line randomly(obviously,they have different height), then teacher tells someone to leave the queue(relative position is not change)to make the left students keep a special queue:

    Assuming that the left students’ numbers are 1, 2,……, m from left to right and their height are T1,T2,……,Tm. Then they satisfy T1<T2<......<Ti, Ti>Ti+1>……>Tm (1<=i<=m).
    Giving you the height of n students (from left to right), please calculate how many students left at most if you want to keep such a special queue.
 

Input

    The first line contains an integer n (2<=n<=1000) represents the number of students.

    The second line contains n integers Ti(150<=Ti<=200) separated by spaces, represent the height(cm) of student i.

Output

    One integer represents the number of the left students.

Sample Input

8186 180 150 183 199 130 190 180

Sample Output

5

n个学生,求满足身高左递增右递减的最长序列 可以没有递增部分或没有递减部分

正序 反序分别求一遍LIS,然后遍历每个点,正序+反序-1 即为结果 -1是因为该点会重复一次

#include 
using namespace std;int dp1[1005],dp2[1005],a[1005],b[1005];int main(){ int n; while(scanf("%d",&n)!=EOF) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); b[n-i+1]=a[i]; } memset(dp1,0,sizeof(dp1)); memset(dp2,0,sizeof(dp2)); dp1[1]=1; dp2[1]=1; for(int i=2;i<=n;i++) { dp1[i]=1; dp2[i]=1; for(int j=1;j

 

转载地址:http://ksio.baihongyu.com/

你可能感兴趣的文章
MySQL 误操作后数据恢复(update,delete忘加where条件)
查看>>
MySQL 调优/优化的 101 个建议!
查看>>
mysql 转义字符用法_MySql 转义字符的使用说明
查看>>
mysql 输入密码秒退
查看>>
mysql 递归查找父节点_MySQL递归查询树状表的子节点、父节点具体实现
查看>>
mysql 通过查看mysql 配置参数、状态来优化你的mysql
查看>>
mysql 里对root及普通用户赋权及更改密码的一些命令
查看>>
Mysql 重置自增列的开始序号
查看>>
mysql 锁机制 mvcc_Mysql性能优化-事务、锁和MVCC
查看>>
MySQL 错误
查看>>
mysql 随机数 rand使用
查看>>
MySQL 面试题汇总
查看>>
MySQL 面试,必须掌握的 8 大核心点
查看>>
MySQL 高可用性之keepalived+mysql双主
查看>>
MySQL 高性能优化规范建议
查看>>
mysql 默认事务隔离级别下锁分析
查看>>
Mysql--逻辑架构
查看>>
MySql-2019-4-21-复习
查看>>
mysql-5.6.17-win32免安装版配置
查看>>
mysql-5.7.18安装
查看>>