动态规划找最长上升子序列,正反遍历一遍序列即可~

#include<bits/stdc++.h>
using namespace std;
const int maxn=;
int N;
int a[maxn];
int l[maxn];
int r[maxn];
int main () {
scanf ("%d",&N);
for (int i=;i<N;i++)
scanf ("%d",&a[i]);
int maxLength=;
int maxIndex;
int maxValue;
int mincha;
for (int i=;i<N;i++) {
for (int j=i-;j>=;j--)
if (a[j]<a[i]) l[i]=max(l[i],l[j]+);
}
for (int i=N-;i>=;i--) {
for (int j=i+;j<N;j++)
if (a[j]<a[i]) r[i]=max(r[i],r[j]+);
}
for (int i=;i<N;i++) {
if (l[i]==||r[i]==) continue;
int len=l[i]+r[i]+;
if (len>maxLength) {
maxLength=len;
maxIndex=i;
mincha=abs(l[i]-r[i]);
}
else if (len==maxLength&&abs(l[i]-r[i])<mincha) {
maxIndex=i;
mincha=abs(l[i]-r[i]);
}
}
if (maxLength==) printf ("No peak shape");
else printf ("%d %d %d",maxLength,maxIndex+,a[maxIndex]);
return ;
}

PAT T1017 The Best Peak Shape的更多相关文章

  1. jellyfish K-mer analysis and genome size estimate

    http://www.cbcb.umd.edu/software/jellyfish/   http://www.genome.umd.edu/jellyfish.html https://githu ...

  2. 1031. Hello World for U (20) PAT

    题目:http://pat.zju.edu.cn/contests/pat-a-practise/1031 分析: 简单题,调整数组的输出次序就可以了. 输入数组长度为len.n1 = n3 = (l ...

  3. PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642 题目描述: Given any string of N (≥5) ...

  4. (论文笔记Arxiv2021)Walk in the Cloud: Learning Curves for Point Clouds Shape Analysis

    目录 摘要 1.引言 2.相关工作 3.方法 3.1局部特征聚合的再思考 3.2 曲线分组 3.3 曲线聚合和CurveNet 4.实验 4.1 应用细节 4.2 基准 4.3 消融研究 5.总结 W ...

  5. OpenCASCADE Shape Location

    OpenCASCADE Shape Location eryar@163.com Abstract. The TopLoc package of OpenCASCADE gives resources ...

  6. Drawable实战解析:Android XML shape 标签使用详解(apk瘦身,减少内存好帮手)

    Android XML shape 标签使用详解   一个android开发者肯定懂得使用 xml 定义一个 Drawable,比如定义一个 rect 或者 circle 作为一个 View 的背景. ...

  7. 《转载》PAT 习题

    博客出处:http://blog.csdn.net/zhoufenqin/article/details/50497791 题目出处:https://www.patest.cn/contests/pa ...

  8. Android GradientDrawable(shape标签定义) 静态使用和动态使用(圆角,渐变实现)

    Android GradientDrawable使用优势: 1. 快速实现一些基本图形(线,矩形,圆,椭圆,圆环) 2. 快速实现一些圆角,渐变,阴影等效果 3. 代替图片设置为View的背景 4. ...

  9. AlloyRenderingEngine之Shape

    写在前面 不读文章,只对代码感兴趣可以直接跳转到这里 https://github.com/AlloyTeam/AlloyGameEngine 然后star一下,多谢支持:). 游戏或者应用中,不是所 ...

随机推荐

  1. 6485. 【GDOI2020模拟02.25】沙塔斯月光

    题目描述 题解 镇♂男则反 如果没有操作3很好办,反着做维护操作1的次数即可 实际上一次操作3的贡献是zi*(∑i到操作1位置的距离) 维护一下即可O(n^4) code #include <b ...

  2. docker 报错 docker: Error response from daemon: driver failed....iptables failed:

    现象: [root@localhost test]# docker run --name postgres1 -e POSTGRES_PASSWORD=password -p : -d postgre ...

  3. Android App测试计划和设计测试矩阵

    Android APP :日程管理APP 测试计划(Test Plan): 编号 测试时间 测试类型 测试计划 1. 5.1~5.5 单元测试 单元测试是由程序员自己来完成,程序员有责任编写功能代码, ...

  4. Educational Codeforces Round 80 (Rated for Div. 2)D(二分答案,状压检验)

    这题1<<M为255,可以logN二分答案后,N*M扫一遍表把N行数据转化为一个小于等于255的数字,再255^2检验答案(比扫一遍表复杂度低),复杂度约为N*M*logN #define ...

  5. springboot的安装与初步使用

    1.引用springboot框架 1.在maven项目底下的pom.xml的中,引用springboot,如下 <?xml version="1.0" encoding=&q ...

  6. Nginx做代理

    0 查看日志 tail -f /var/log/nginx/access.log 1 Nginx代理配置语法 1.Nginx代理配置语法 Syntax: proxy_pass URL; Default ...

  7. django 模版查找路径

    路径的配置,模版上下文的配置等.模版路径可以在两个地方配置. 1.'DIRS':这是一个列表,在这个列表中可以存放所有的模版路径,以后在视图中使用render或者render_to_string渲染模 ...

  8. python pip 安装常用库如何使用国内镜像源

    最近通过python安装一些常用库发现下载速度特别慢,而且还会出现无法安装等错误,尝试找了一些国内的镜像源,发现阿里云的速度很快,这里做个记录,并分享给大家. 国内镜像源 阿里云:http://mir ...

  9. django 项目发布(centos 6.5 + python 3.5 + django1.9.8 + paramiko 2.0.2 + gunicorn )

    环境 os centos 6.5 64bit python 3.5 django 1.9.8 paramiko 2.0.2 gunicorn 19.6.0 安装 centos install pyth ...

  10. opencv:图像卷积

    卷积基本概念 C++代码实现卷积 #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; u ...