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 ...
随机推荐
- Hub control
Hub(中心) 中心页是用户进入应用的入口点.中心页在丰富的平移视图中显示内容,这样用户一眼就能看见新鲜有趣的内容,从而吸引他们深入了解你的应用中的更多内容.中心显示不同的内容类别,每个类别映射到应用 ...
- iOS 技术博客分享
1.了解有什么新技术 1> 苹果API文档 - General - Guides - iOSx API Diffs 2> 观看WWDC会议视频 2.如何使用新技术 1> 自己根据AP ...
- ubuntu下svn使用指南
ubuntu下安装subversion客户端: sudo apt-get install subversion subversion-tools 详细请看 http://www.subversion. ...
- ERROR 1045 (28000): Access denied for user root@localhost (using password:
错误描述: Mysql中添加用户之后可能出现登录时提示ERROR 1045 (28000): Access denied for user的错误.删除user.user中值为NULL的,或更新NULL ...
- VS活动解决方案平台
测试环境:win7 x64 测试程序:WCF查询数据库后将数据集返回到Winform程序加载并显示 测试结果: 1.从感觉来说Exe在 x86目标平台生成,启动速度快. 2.内存消耗:x86的程序在超 ...
- 西门子MES解决方案SIMATIC IT在乳制品行业小试牛刀
竞争的白热化,紧缩的产品利润,食品安全保障,越来越苛刻的法规要求和全球化的市场与品牌维持的重要性对乳品行业的企业提出了更高的要求,实施 MES将是企业唯一的出路. 自从“十一五”制造业信息化为MES正 ...
- 小课堂week14 Google软件测试之道
读<Google软件测试之道> 在IT领域,Google是一面旗帜,是一家非常善于思考善于尝试的公司.随着面临挑战的不断增大,传统的测试开展方式也越来越力不从心,这本书讲述的就是一次完整的 ...
- Tostring记录,方便自己查看
C 货币 2.5.ToString("C") ¥2.50 D 十进制数 25.ToString("D5") 00025 E 科学型 25000.ToString ...
- python去掉空行
#用strip(),split()两个方法都可以判断空行 infile=open('/.../','r') outfile=open('/.../','w') for li in infile.rea ...
- this的使用方法
当一个对象创建后,Java虚拟机(JVM)就会给这个对象分配一个引用自身的指针,这个指针的名字就是this.this是指向对象本身的一个指针.this只和特定的对象关联,而不和类关联,同一个类的不同对 ...