DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
/*
DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生:
1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + 1
2. l[i-1] + 1 3. r[i+1] + 1 //修改a[i]
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int l[MAXN], r[MAXN];
int n; int main(void) //Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
{
scanf ("%d", &n); int ans = ;
for (int i=; i<=n; ++i)
{
scanf ("%d", &a[i]);
l[i] = ;
if (i > && a[i] > a[i-]) l[i] = l[i-] + ;
} for (int i=n; i>=; --i)
{
r[i] = ;
if (i < n && a[i] < a[i+]) r[i] = r[i+] + ;
} for (int i=; i<=n; ++i)
{
ans = max (ans, l[i]); ans = max (ans, r[i]);
if (i > && i < n && a[i-] + < a[i+]) ans = max (ans, l[i-] + r[i+] + );
if (i > ) ans = max (ans, l[i-] + );
if (i < n) ans = max (ans, r[i+] + );
} printf ("%d\n", ans); return ;
}
DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences的更多相关文章
- Codeforces Round #FF (Div. 1) A. DZY Loves Sequences 动态规划
A. DZY Loves Sequences 题目连接: http://www.codeforces.com/contest/446/problem/A Description DZY has a s ...
- Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
题目链接: http://www.codeforces.com/contest/446/problem/A 题解: dp1[x]表示以x结尾的最大严格升序连续串,dp2[x]表示以x开头的最大严格升序 ...
- Codeforces Round #FF (Div. 2) C. DZY Loves Sequences
解题报告:输入一个数列,选取一个子数列,要求最多只能改动这个子数列中的一个数,使得这个子数列是严格的升序的(严格升序没有相等的) 我的做法是,第一步把这个 数列的每个升序的子数列都找出来,然后看这些子 ...
- Codeforces Round #FF (Div. 1) B. DZY Loves Modification 优先队列
B. DZY Loves Modification 题目连接: http://www.codeforces.com/contest/446/problem/B Description As we kn ...
- Codeforces Round #FF (Div. 2) D. DZY Loves Modification 优先队列
D. DZY Loves Modification time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #FF (Div. 1) B. DZY Loves Modification
枚举行取了多少次,如行取了i次,列就取了k-i次,假设行列单独贪心考虑然后相加,那么有i*(k-i)个交点是多出来的:dpr[i]+dpc[k-i]-i*(k-i)*p 枚举i取最大值.... B. ...
- Codeforces Round #FF (Div. 2):B. DZY Loves Strings
B. DZY Loves Strings time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #FF (Div. 2)__E. DZY Loves Fibonacci Numbers (CF447) 线段树
http://codeforces.com/contest/447/problem/E 题意: 给定一个数组, m次操作, 1 l r 表示区间修改, 每次 a[i] + Fibonacci[i-l ...
- Codeforces Round #FF (Div. 2) A. DZY Loves Hash
DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the ...
随机推荐
- 【Github】如何删除github上的项目
1.登录你的githup账户,进入到仓库页面如下图 2.点击setting进入到该仓库的设置界面 3.复制一下仓库的名称,然后下拉到最后,点击delete this repository 4.将刚刚复 ...
- Flink本地安装和创建Flink应用
本篇文章首发于头条号Flink本地安装和创建Flink应用,欢迎关注我的头条号和微信公众号"大数据技术和人工智能"(微信搜索bigdata_ai_tech)获取更多干货,也欢迎关注 ...
- java常用工具类 - 全角转半角、半角转全角
全角转半角.半角转全角代码 /** * <PRE> * 提供对字符串的全角->半角,半角->全角转换 * codingwhy.com * </PRE> */ pub ...
- css 實現微信聊天類似的氣泡
要實現這樣的效果 代碼如下: --------------------------------------- <style> .test{width:300px; padding:30px ...
- CentOS 7 防火墙开启了哪些服务和端口?
过滤封包功能的 netfilter 已经内建在 CentOS 7 的内核,但是配置 netfilter 的界面程式 firewalld 却未必有安装,不论是否已经安装,都可以执行下面的安装指令: yu ...
- 人脸识别“Neural Aggregation Network for Video Face Recognition”
人脸识别的新方法.主要对视频进行处理.使用CNN提取视频中多帧人像的特征,之后使用聚合模块对全部帧的特征向量进行学习累积.实验结果表明这样的方法比手工设计的方法如平均池化要好.人脸识别结构例如以下图所 ...
- Android关于Task的一些实践之SingleTask, SingleInstance和TaskAffinity
上一篇文章粗略地介绍了一下关于Android中Task的基本知识.只是实践才是检验真理的唯一标准,所以.今天就来试验一下Task中的launchMode是否真的实现了文档所说的那样. 首先.定义三个A ...
- 关于The hierarchy of the type TestBeforeAdvice is inconsistent的问题
今天准备写一个spring aop的demo,创建了TestBeforeAdvice类,该类实现了MethodBeforeAdvice接口,eclipse报了"The hierarchy o ...
- 解决Eclipse alt+/不出来提示的问题
1. 检查windows ——preferences ——java ——editor —— content assist - advanced,在右上方有一行“select the proposal ...
- APDU报文【转】
本文转载自:http://www.cnbolgs.com/snail0404/p/5436348.html APDU # APDU # 定义:APDU(ApplicationProtocolDat ...