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 ...
随机推荐
- PHP生成二维码库phpqrcode
Description PHP QR Code is open source (LGPL) library for generating QR Code, 2-dimensional barcode. ...
- PHP+ajax聊天室源码!支持长轮循跟定时请求两种
var lastID = "1";//声明上次取回的消息的ID var isposted = false; var mGetTime;//设置setTimeout的返回值 // ...
- css3圆角边框,边框阴影
border-radius向元素添加圆角边框,css3中的.IE9+ chrome safari5+ firefox4+ 现在都支持.可以向input div等设置边框.与border相似,可以四个角 ...
- 【深入比较ThreadLocal模式与synchronized关键字】
[深入比较ThreadLocal模式与synchronized关键字]ThreadLocal模式与synchronized关键字都是用于处理多线程并发访问变量的问题.只是两者处理问题的角度和思路不同. ...
- VPS centos 6 安装图形界面
在某种场合之下,我们使用的Linux还是要选择安装桌面环境的,所以在这里介绍一下如何给没有安装桌面环境的系统安装桌面环境.以Centos 6.5 为例演示一下如何安装桌面环境. 工具/原料 Linux ...
- MSSQL 所有表中模糊查询
--搜索指定数据在那个对象中存在.txt(所有表中模糊查询) CREATE PROC sp_ValueSearch @value sql_variant, --要搜索的数据 @precision bi ...
- Oracle 直方图理论
一.何为直方图 直方图是一种几何形图表,它是根据从生产过程中收集来的质量数据分布情况,画成以组距为底边.以频数为高度的一系列连接起来的直方型矩形图,如图所示 二.ORACLE 直方图 在Oracle中 ...
- 【坑】log4j-over-slf4j.jar AND slf4j-log4j12.jar的冲突问题
为了解决这个问题,已经有砸电脑的冲动了.通过百度查找都说是Maven依赖的原因,经过各种尝试仍然没有解决,后来终于在QQ群的帮助下,算是暂时过关. [问题] 程序在本地运行没有问题,打成jar包发布到 ...
- iOS开发常用的宏
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)#define SCREEN_HEIGHT ([UIScreen mainS ...
- Python性能优化的20条建议 (转载)
优化算法时间复杂度 算法的时间复杂度对程序的执行效率影响最大,在Python中可以通过选择合适的数据结构来优化时间复杂度,如list和set查找某一个元素的时间复杂度分别是O(n)和O(1).不同的场 ...