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

#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. Go文件拷贝

    package main import ( "os" "io" "fmt" "io/ioutil" ) func mai ...

  2. * ./common/http.js in ./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-opt

    vue项目报错如下,找到原因之后,其实超简单,请看: 原来是引入文件路径出现问题,想起刚刚引入了一个文件,一修改,果然药到病除! ----------------------------------- ...

  3. CRPR/CPPR

    S CRPR  clock reconvergence pessimism removal C CPPR  clock path pessimism removal 剔除公共clock path上的悲 ...

  4. argparse 模块使用

    import argparse,os data_func=["upload","download"]req_func=["getfunc", ...

  5. C++记录(一)

    1 extern 符表示该变量不是当前作用域定义的,用于声明. 如extern i;表示i不是当前作用域里的,是其他某个include的cpp文件里的变量. 2 int *p=0;相当于初始化p为空指 ...

  6. Python连载59-HTTP首部字段和消息头,Thinker简介

    一.首部字段或者消息头 1.下面几个类型都是请求的: User-Agent:关于浏览器和它平台的消息,如Mozilla5.0 Accept:客户端能处理的页面的类型,如text/html Accept ...

  7. Jmeter-ServerAgent

    You can specify the listening ports as arguments (0 disables listening), default is 4444:   $ ./star ...

  8. Django--模型管理器

    参考https://blog.csdn.net/qq_34788903/article/details/87889451 可参考视频 :  https://www.bilibili.com/video ...

  9. 洛谷P1734 最大约数和(01背包)

    题目描述 选取和不超过S的若干个不同的正整数,使得所有数的约数(不含它本身)之和最大. 输入格式 输入一个正整数S. 输出格式 输出最大的约数之和. 输入输出样例 输入 #1 11 输出 #1 9 说 ...

  10. P3368 (模板)树状数组2

    借这个题学新姿势,这个题需要利用差分才能AC,普通树状树有3个点过不了. 差分原理(参考题解区大佬): 一个例子,一组数据 $ a[] = { 1, 5, 4, 2, 3 } $,差分后得到 $ b[ ...