PAT T1017 The Best Peak Shape
动态规划找最长上升子序列,正反遍历一遍序列即可~
#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的更多相关文章
- jellyfish K-mer analysis and genome size estimate
http://www.cbcb.umd.edu/software/jellyfish/ http://www.genome.umd.edu/jellyfish.html https://githu ...
- 1031. Hello World for U (20) PAT
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1031 分析: 简单题,调整数组的输出次序就可以了. 输入数组长度为len.n1 = n3 = (l ...
- 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) ...
- (论文笔记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 ...
- OpenCASCADE Shape Location
OpenCASCADE Shape Location eryar@163.com Abstract. The TopLoc package of OpenCASCADE gives resources ...
- Drawable实战解析:Android XML shape 标签使用详解(apk瘦身,减少内存好帮手)
Android XML shape 标签使用详解 一个android开发者肯定懂得使用 xml 定义一个 Drawable,比如定义一个 rect 或者 circle 作为一个 View 的背景. ...
- 《转载》PAT 习题
博客出处:http://blog.csdn.net/zhoufenqin/article/details/50497791 题目出处:https://www.patest.cn/contests/pa ...
- Android GradientDrawable(shape标签定义) 静态使用和动态使用(圆角,渐变实现)
Android GradientDrawable使用优势: 1. 快速实现一些基本图形(线,矩形,圆,椭圆,圆环) 2. 快速实现一些圆角,渐变,阴影等效果 3. 代替图片设置为View的背景 4. ...
- AlloyRenderingEngine之Shape
写在前面 不读文章,只对代码感兴趣可以直接跳转到这里 https://github.com/AlloyTeam/AlloyGameEngine 然后star一下,多谢支持:). 游戏或者应用中,不是所 ...
随机推荐
- 利用mnist训练集生成的caffemodel对mnist测试集与自己手写的数字进行测试
从一到二:利用mnist训练集生成的caffemodel对mnist测试集与自己手写的数字进行测试 通过从零到一的教程,我们已经得到了通过mnist训练集生成的caffemodel,主要包含下面四个文 ...
- React源码解析之React.Children.map()(五)
一,React.Children是什么? 是为了处理this.props.children(this.props.children表示所有组件的子节点)这个属性提供的工具,是顶层的api之一 二,Re ...
- [LEETCODE] 初级算法/数组 1.3旋转数组
原题: 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数. 示例 1: 输入: [1,2,3,4,5,6,7] 和 k = 3 输出: [5,6,7,1,2,3,4] 解释: 向右 ...
- CentOS7安装jdk教程
引言Oracle JDK和OpenJDK的简单介绍Oracle JDK是基于Java标准版规范实现的,以二进制产品的形式发布.它支持多种操作系统,如Windows,Linux,Solaris,MacO ...
- unittest 测试套件使用汇总篇
# coding=utf-8import unittestfrom inspect import isfunction def usage(): """also unit ...
- SQL注入--sqli-labs(1-4关)
Less_1 查库:select schema_name from information_schema.schemata 查表:select table_name from information_ ...
- Git远程推送和抓取分支
查看远程库信息 当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了,并且,远程仓库的默认名称是origin.要查看远程库的信息,用git remote,或 ...
- 国密SM9算法C++实现(Linux)
首先参考 Linux下编译并使用miracl密码库 该博文在linux下编译Miracl库. 编译完了,自然是要用的,下面介绍两种在C程序中使用miracl库的方法. 方法一: 1. 源码编译完后的必 ...
- List(数组)里面常用的属性和方法
常用属性: length 长度 reversed 翻转 isEmpty 是否为空 isNotEmpty 是否不为空常用方法: add 增加 addAll 拼接数组 增加多个数据 list.addAll ...
- Android学习02
今天学了ScrollView&HorizontalScrollView和WebView 一.ScrollView(垂直滚动),HorizontalScrollView(水平滚动) Scroll ...