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 ...
随机推荐
- How many ways?? 矩阵快速幂 邻接矩阵意义
春天到了, HDU校园里开满了花, 姹紫嫣红, 非常美丽. 葱头是个爱花的人, 看着校花校草竞相开放, 漫步校园, 心情也变得舒畅. 为了多看看这迷人的校园, 葱头决定, 每次上课都走不同的路线去教室 ...
- [bzoj3436]小K的农场_差分约束
小K的农场 bzoj-3436 题目大意:给定n个点,每个节点有一个未知权值.现在有m个限制条件,形如:点i比点j至少大c,点i比点j至多大c或点i和点j相等.问是否可以通过给所有点赋值满足所有限制条 ...
- Validate Binary Search Tree(DFS)
Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...
- hadoop(2)hadoop配置
hadoop入门(二) hadoop的配置 1.本地模式 2.伪分布式 3.分布式 一.配置linux环境: 1打开虚拟网络编辑器,选择 VMnet1 仅主机模式, 子网 IP 设为 192. ...
- Ubuntu系统备份工具大全(官方整理推荐)
其实官方在系统备份这块已经有Wiki整理和收集各类实用的工具.以下是翻译自官方Wiki的部分文档: 备份工具 wiki文档实用程序 工具 界面 格式类型 Raw/File 支持 远程 增量 差异 自 ...
- Builder设计模式
Builder模式,又称生成器或构建者模式,属于对象创建型模式,侧重于一步一步的构建复杂对象,只有在构建完成后才会返回生成的对象.Builder模式将一个复杂对象的构建与它的表示分离,使得同样的构建过 ...
- Oldboy 基于Linux的C/C++自动化开发---MYSQL
http://www.eimhe.com/forum.php?mod=viewthread&tid=142952#lastpost http://www.eimhe.com/thread-14 ...
- Python学习系列之反射
反射的定义 根据字符串的形式去某个对象中操作成员 根据字符串的形式去某个对象中寻找成员 根据字符串的形式去某个对象中设置成员 根据字符串的形式去某个对象中删除成员 根据字符串的形式去某个对象中判断成员 ...
- MySQL 高可用架构在业务层面的分析研究
)读多写少 虚线表示跨机房部署,比方电子商务系统.一个Master既有读也有些写.对读数据一致性须要比較重要的.读要放在Master上面. M(R)仅仅是一个备库.仅仅有M(WR)挂了之后,才会切换到 ...
- Oracle Warehouse Builder(OWB) 安装报seeding owbsys错误的解决
今天在RHEL6.4上安装Oracle Warehouse Builder 11.2时在最后一步报错,打开日志查看有例如以下信息: main.TaskScheduler timer[5]2014052 ...