Codeforces 447 C DZY Loves Sequences【DP】
题意:给出一列数,在这个序列里面找到一个连续的严格上升的子串,现在可以任意修改序列里面的一个数,问得到的子串最长是多少
看的题解,自己没有想出来
假设修改的是a[i],那么有三种情况,
1.a[i]>a[i-1],那么求出向左能够延伸的最长的长度
2.a[i]<a[i-1],那么求出向右能够延伸的最长的长度
3.如果修改的这个数刚好夹在两个数的中间,这种情况比上面两种都优, 即为a[i-1]<a[i+1]-1,求出左右能够延伸的最长的长度
然后因为a[i]本身还没有算进去,所以求出最大值后,再加个1 参看的这一篇http://blog.csdn.net/hongrock/article/details/37754307
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=;
int a[maxn],l[maxn],r[maxn]; int main(){
int n;
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=n;i++) {
l[i]=;r[i]=;
} for(int i=n-;i>=;i--) if(a[i]<a[i+]) r[i]+=r[i+]; int ans=;
for(int i=;i<=n;i++) if(a[i]>a[i-]) l[i]+=l[i-]; l[]=-;r[n+]=-;
a[]=INF;a[n+]=-;
for(int i=;i<=n;i++){
if(a[i-]<a[i+]-) ans=max(ans,l[i-]+r[i+]+);
else ans=max(ans,max(l[i-],r[i+])+);
}
printf("%d\n",ans);
return ;
}
Codeforces 447 C DZY Loves Sequences【DP】的更多相关文章
- Codeforces 445 A DZY Loves Chessboard【DFS】
题意:给出n*m的棋盘,在‘.’处放上B或者W,最后要求所有的B和W都不相邻 先把棋盘的点转化成‘B’,再搜,如果它的四周存在‘B’,则将它变成'W' 一直挂在第五个数据的原因是,没有dfs(nx,n ...
- codeforces#FF DIV2C题DZY Loves Sequences(DP)
题目地址:http://codeforces.com/contest/447/problem/C C. DZY Loves Sequences time limit per test 1 second ...
- [CodeForces - 447C] C - DZY Loves Sequences
C - DZY Loves Sequences DZY has a sequence a, consisting of n integers. We'll call a sequence ai, ai ...
- Codeforces 446A. DZY Loves Sequences (线性DP)
<题目链接> 题目大意: 给定一个长度为$n$的序列,现在最多能够改变其中的一个数字,使其变成任意值.问你这个序列的最长严格上升子段的长度是多少. #include <bits/st ...
- CodeForces - 446A DZY Loves Sequences(dp)
题意:给定一个序列a,求最长的连续子序列b的长度,在至多修改b内一个数字(可修改为任何数字)的条件下,使得b严格递增. 分析: 1.因为至多修改一个数字,假设修改a[i], 2.若能使a[i] < ...
- CF446A DZY Loves Sequences 简单dp
DZY has a sequence a, consisting of n integers. We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ...
- codeforces 445 B DZY Loves Chemistry【并查集】
题意:给出n种化学物质,其中m对会发生化学反应,每次加入化学物质进去的时候, 如果有能够和它发生反应的,危险值就乘以2,问怎样的放入顺序使得危险值最大 将这m对会反应的用并查集处理,统计每个连通块里面 ...
- HDU 5656 ——CA Loves GCD——————【dp】
CA Loves GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- codeforces 2B The least round way 【DP】
VJ上可找到中文题意. 思路: 首先分解有多少2与多少5.接下来就是dp. 分两次,一次是根据2的数量贪心,另外一次是根据5的数量贪心,看哪一次乘积的末尾0最少. 需要注意的是两点: 1.输入有0的情 ...
随机推荐
- UnityException: Texture is not readable
原地址:http://blog.csdn.net/emoonight/article/details/18002913 fore you can save or load a Texture, you ...
- http authorization basic请求代码示例
/** * */ package testJava.java; import java.io.BufferedReader; import java.io.InputStream; import ja ...
- FIN_WAIT1 能持续多久?你知道吗
FIN_WAIT1 能持续多久?你知道吗 2016-01-12 运维帮 原文:http://blogread.cn/it/article/7215?f=wb&luicode=10000359 ...
- jmeter学习预热
对jmeter有些兴趣,最近想抽点时间熟悉下,个人熟悉某个工具的方法: 1.官网http://jmeter.apache.org/,一般官网会有Tutorials或者Getting Started之类 ...
- 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第六章 1(Lists)
127 - "Accordian" Patience 题目大意:一个人一张张发牌,如果这张牌与这张牌前面的一张或者前面的第三张(后面称之为一位置和三位置)的点数或花式相同,则将这张 ...
- 关于SQL查询效率,100w数据,查询只要1秒
1.关于SQL查询效率,100w数据,查询只要1秒,与您分享:机器情况p4: 2.4内存: 1 Gos: windows 2003数据库: ms sql server 2000目的: 查询性能测试,比 ...
- 【LA3942-Remember the word 】Trie
http://acm.hust.edu.cn/vjudge/problem/22109 题意:给定n个单词,一个字符串,问把这个字符串划分为若干个单词的连接(单词可重复使用)有多少种方案(mod200 ...
- React组件生命周期-正确执行运行阶段的函数
一. 二. <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset=" ...
- Cornerstone问题
// Cornerstone锁 Cornerstone locks a working copy whenever it performs operations suchs as commits, u ...
- Sublime Text2 多行编辑快捷键
鼠标选中多行,按下 Ctrl Shift L (Command Shift L) 即可同时编辑这些行:鼠标选中文本,反复按 CTRL D (Command D) 即可继续向下同时选中下一个相同的文本进 ...