题意:给出一列数,在这个序列里面找到一个连续的严格上升的子串,现在可以任意修改序列里面的一个数,问得到的子串最长是多少

看的题解,自己没有想出来

假设修改的是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】的更多相关文章

  1. Codeforces 445 A DZY Loves Chessboard【DFS】

    题意:给出n*m的棋盘,在‘.’处放上B或者W,最后要求所有的B和W都不相邻 先把棋盘的点转化成‘B’,再搜,如果它的四周存在‘B’,则将它变成'W' 一直挂在第五个数据的原因是,没有dfs(nx,n ...

  2. codeforces#FF DIV2C题DZY Loves Sequences(DP)

    题目地址:http://codeforces.com/contest/447/problem/C C. DZY Loves Sequences time limit per test 1 second ...

  3. [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 ...

  4. Codeforces 446A. DZY Loves Sequences (线性DP)

    <题目链接> 题目大意: 给定一个长度为$n$的序列,现在最多能够改变其中的一个数字,使其变成任意值.问你这个序列的最长严格上升子段的长度是多少. #include <bits/st ...

  5. CodeForces - 446A DZY Loves Sequences(dp)

    题意:给定一个序列a,求最长的连续子序列b的长度,在至多修改b内一个数字(可修改为任何数字)的条件下,使得b严格递增. 分析: 1.因为至多修改一个数字,假设修改a[i], 2.若能使a[i] < ...

  6. 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 ...

  7. codeforces 445 B DZY Loves Chemistry【并查集】

    题意:给出n种化学物质,其中m对会发生化学反应,每次加入化学物质进去的时候, 如果有能够和它发生反应的,危险值就乘以2,问怎样的放入顺序使得危险值最大 将这m对会反应的用并查集处理,统计每个连通块里面 ...

  8. HDU 5656 ——CA Loves GCD——————【dp】

    CA Loves GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)To ...

  9. codeforces 2B The least round way 【DP】

    VJ上可找到中文题意. 思路: 首先分解有多少2与多少5.接下来就是dp. 分两次,一次是根据2的数量贪心,另外一次是根据5的数量贪心,看哪一次乘积的末尾0最少. 需要注意的是两点: 1.输入有0的情 ...

随机推荐

  1. PHP PDO_MYSQL 操作类 YAF嵌入高性能类而准备

    https://github.com/indieteq/PHP-MySQL-PDO-Database-Class PHP-PDO-MySQL-Class A PHP MySQL PDO class s ...

  2. javascript中的JSON序列化与反序列化

    简单粗暴上代码: function create() { this.name = "jack"; this.sex = "man"; } create.prot ...

  3. iOS视频压缩

    // // ViewController.m // iOS视频测试 // // Created by apple on 15/8/19. // Copyright (c) 2015年 tqh. All ...

  4. 错误 1 无法嵌入互操作类型“Microsoft.Office.Interop.Excel.ApplicationClass”。请改用适用的接口

    http://www.cnblogs.com/waitingfor/archive/2011/12/19/2293469.html

  5. SQL 递归查询

    WITH B (FATHER,SON,ID,ALLINFO) AS (SELECT RTRIM(LTRIM(CHAR(A.ID)))|| CHAR(ROW_NUMBER() OVER(PARTITIO ...

  6. Android Grapics图像类体系

  7. phantomjs + selenium headless test

    1. 安装selenium pip install selenium 2. 安装phantomjs 如果你是Ubuntu12.04,默认安装的版本是1.4.这个会出错. 需要安装1.9.7 cd /u ...

  8. Android 实现全屏、无标题栏

    实现全屏无标题栏: 1.在xml文件中进行配置 AndroidManifest.xml中,找到需要全屏或设置成无标题栏的Activity,在该Activity进行如下配置即可. 实现全屏效果: and ...

  9. android 广播的使用

    在Activity中,注册广播的一个Demo. 总共分3步 第一步:定义一个BroadcastReceiver广播接收类: private BroadcastReceiver mBroadcastRe ...

  10. ace-min.css

    textarea,input[type="text"],input[type="password"],input[type="datetime&quo ...