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 ...
随机推荐
- WebClient模拟发送Post请求
WebClient模拟发送Post请求方法: /// <summary> /// 模拟post请求 /// </summary> /// <param name=&quo ...
- c#自定义控件属性面板及选择资源设置
博客转移到 http://jacean.github.io/ 继续分享编程经验 因为要做流体布局,但两个控件没办法组合,就做自定义控件.这个控件需要一个text设置文本,一个pic设置图片显示,图片通 ...
- 由window.history.back()引发的问题
由window.history.back()引发的问题 编写人:CC阿爸 2015-1-30 今天在这里,我想与大家一起分享由windows.history.back()引发的问题,笔者在实际开发当中 ...
- silverlight 获取路径 config
1.获取web.config配置内容: web.config default.aspx protected string InitParams { get; set; } InitParams = s ...
- mariadb的explain分析及InnoDB存储引擎
id: 当前查询语句中,每个SELECT语句的编号, id: 1 表示简单类型的查询 复杂类型的查询有三种:简单子查询,用于FROM中的子查询,联合查询:UNION 注意:UNION查询的分 ...
- 用js读、写、删除Cookie
//已经验证过 // JavaScript Document //使用说明: //设置缓存:setCookie("name",value); //获取缓存:var name=ge ...
- 03-树3 Tree Traversals Again
二叉树及其遍历 push为前序遍历序列,pop为中序遍历序列.将题目转化为已知前序.中序,求后序. 前序GLR 中序LGR 前序第一个为G,在中序中找到G,左边为左子树L,右边为右子树R. 将左右子树 ...
- python的egg包的安装和制作]
Defining Python Source Code Encodings Python egg 的安装 egg文件制作与安装 2011-06-10 14:22:50| 分类: python | ...
- object sender ,EventArs e
引用:http://blog.csdn.net/kongbai308416350/article/details/4233786 说的通俗一些,就是: 有一个叫做EventHandler 的家伙,他会 ...
- DrawerLayout带有侧滑功能的布局类(2)
ActionBarDrawerToggle: 在前一张中我们并没有使用drawLayout.setDrawerListener(); 对应的参数对象就是DrawerLayout.DrawerListe ...