Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
题目链接:
http://www.codeforces.com/contest/446/problem/A
题解:
dp1[x]表示以x结尾的最大严格升序连续串,dp2[x]表示以x开头的最大严格升序连续串
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<list>
#include<stack>
#include<algorithm>
using namespace std; const int maxn = + ;
const int INF = 2e9;
typedef __int64 LL; int n;
int dp1[maxn], dp2[maxn];
int arr[maxn]; void init() {
memset(dp1, , sizeof(dp1));
memset(dp2, , sizeof(dp2));
} int main() {
while (scanf("%d", &n) == && n) {
init();
for (int i = ; i < n; i++) scanf("%d", arr + i);
dp1[] = ;
for (int i = ; i < n; i++) {
if (arr[i] > arr[i - ]) dp1[i] = dp1[i - ] + ;
else dp1[i] = ;
}
dp2[n - ] = ;
for (int i = n - ; i >= ; i--) {
if (arr[i] < arr[i + ]) dp2[i] = dp2[i + ] + ;
else dp2[i] = ;
}
int ans = max(dp2[] + , dp1[n - ]+);
for (int i = ; i < n - ; i++) {
if (arr[i - ] < arr[i + ] - ) ans = max(ans, dp1[i - ] + + dp2[i + ]);
else {
ans = max(ans,dp1[i - ] + );
ans = max(ans,dp2[i + ] + );
}
}
printf("%d\n", ans);
}
return ;
}
Codeforces Round #FF (Div. 1) A. DZY Loves Sequences的更多相关文章
- 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] + ...
- 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. 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 ...
随机推荐
- [terry笔记]RMAN综合学习之配置
[terry笔记]RMAN综合学习之备份http://www.cnblogs.com/kkterry/p/3308405.html [terry笔记]RMAN综合学习之恢复 http://www.cn ...
- 在MAC OS 下配置python + Flask ,并支持pyCharm编辑器
原创咯- flask是一个micro framework ,伸缩性很强.可以部署到openshift 的PAAS里.这个框架上手非常快.喜欢的可以试试. 若实在MAC里,python已经默认安装了.1 ...
- SQL语句中各种数据类型转换方法总结
1.Access 每个函数都可以强制将一个表达式转换成某种特定数据类型. 语法 CBool(expression) CByte(expression) CCur(expression) CDate(e ...
- 关于Haproxy安装和配置:负载配置【haproxy.cfg】问题记录
1. 存放地址: more /etc/haproxy/haproxy.cfg ps -ef | grep haproxy 看看有没有haproxy的进程就是了 或者看看服务器的23306的端口有没有 ...
- .NET开源工作流RoadFlow-流程设计-流程属性设置
打开流程设计器点击新建流程后会弹出新流程属性设置框,属性设置包括基本信息,数据连接和标识字段三项设置. 1.基本信息 流程ID:系统自动给每个流程分配的一个唯一ID. 流程名称:给您的新流程取一个名称 ...
- Linux中JDK环境变量的配置
在JDK安装好以后,需要进行环境变量的配置 配置目录 /etc/profile 在这个文件的末尾追加 JAVA_HOME=/home/j2sdk1.4.2_11PATH=$PATH:/home/j ...
- ORA-01207: file is more recent than control file -
OS: [root@yoon ~]# more /etc/oracle-releaseOracle Linux Server release 5.7 DB: Oracle Database 11g E ...
- 详谈 oracle 索引 (笔记)
1.oracle索引空值问题 当在有空值得列上建立单列索引时,如果搜索条件为 is null 在解释计划中可以看到,对于此列oracle并没有使用索引查询: 但是当建立的是多列索引是,就会按照索引来进 ...
- JVM学习总结五(番外)——JConsole
之前本来打算结合自己写的小程序来介绍JConsole和VirtualVM的使用的,但是发现很难通过一个程序把所有的场景都体现出来,所以还是决定用书中的典型小例子来讲更加清晰. 一.JConsole的基 ...
- libevent 定时器示例
程序执行结果: 每隔2秒,触发一次定时器. (2)98行:evtimer_assign在event.h中定义如下: 再来看看event_assign函数: ev 要初始化的事件对象 base ...