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一下,多谢支持:). 游戏或者应用中,不是所 ...
随机推荐
- EVE-NG镜像模板资源占用统计
转:http://www.emulatedlab.com/forum.php?mod=viewthread&tid=432&extra=page%3D1 EVE Image fold ...
- vue简单计数器
//App.vue <template> <div id="app"> <!-- <img src="./assets/logo.pn ...
- 转载:initcall
转自:http://blog.chinaunix.net/uid-29570002-id-4387097.html Linux系统启动过程很复杂,因为它既需要支持模块静态加载机制也要支持动态加载机制. ...
- Yii2中事务的使用
官方是这样的 // $connection其实是数据库连接$transaction = $connection->beginTransaction(); try { $connection-&g ...
- pysftp-tools
import pysftp import paramiko import os import unittest import json import warnings warnings.filterw ...
- 爬虫 - Scrapy中间件
前提:看Scrapy架构图 不管什么Middlewares,都写在middlewares.py里面. 然后在settings.py里的DOWNLOADER_MIDDLEWARES或者SPIDER_MI ...
- casperJs的安装
自己买了vps就是爽,想装什么就装什么.就比如说casperjs 1.首先需要安装它的运行环境phantomjs *将这个git项目clone到自己的vps上[https://github.com/a ...
- Python中的bool类型
Python 布尔类型 bool python 中布尔值使用常量True 和 False来表示:注意大小写 比较运算符< > == 等返回的类型就是bool类型:布尔类型通常在 if 和 ...
- java篇 之 集合
集合 链接:https://blog.csdn.net/weixin_42504145/article/details/83119088 数组: java的数组既可以存储基本数据类型,也可以存储引 ...
- 使用node查询数据库(mysql)时,日期格式不对的问题。
https://blog.csdn.net/chanlingmai5374/article/details/93190983 1.问题场景 数据库里存了 datetime.但 Node 查询出来是这样 ...