博客
关于我
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学习总结(51)——Linux主机Mysql数据库自动备份
查看>>
Mysql学习总结(52)——最全面的MySQL 索引详解
查看>>
Mysql学习总结(53)——使用MySql开发的Java开发者规范
查看>>
Mysql学习总结(54)——MySQL 集群常用的几种高可用架构方案
查看>>
Mysql学习总结(55)——MySQL 语句大全再温习
查看>>
Mysql学习总结(56)——MySQL用户管理和权限设置
查看>>
Mysql学习总结(57)——MySQL查询当天、本周、本月、上周、本周、上月、距离当前现在6个月数据
查看>>
Mysql学习总结(58)——深入理解Mysql的四种隔离级别
查看>>
Mysql学习总结(59)——数据库分库分表策略总结
查看>>
Mysql学习总结(5)——MySql常用函数大全讲解
查看>>
Mysql学习总结(60)——并发量大、数据量大的互联网业务数据库设计规范总结
查看>>
Mysql学习总结(61)——MySQL优化之DBA级优化整理汇总
查看>>
Mysql学习总结(62)——MySQL连接com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link问题
查看>>
Mysql学习总结(63)——Mysql数据库架构方案选择与分析
查看>>
Mysql学习总结(64)——Mysql配置文件my.cnf各项参数解读
查看>>
Mysql学习总结(65)——项目实战中常用SQL实践总结
查看>>
Mysql学习总结(66)——设置MYSQL数据库编码为UTF-8
查看>>
Mysql学习总结(67)——MYSQL慢查询日志
查看>>
Mysql学习总结(68)——MYSQL统计每天、每周、每月、每年数据 SQL 总结
查看>>
Mysql学习总结(69)——Mysql EXPLAIN 命令使用总结
查看>>