解题报告:输入一个数列,选取一个子数列,要求最多只能改动这个子数列中的一个数,使得这个子数列是严格的升序的(严格升序没有相等的)

我的做法是,第一步把这个 数列的每个升序的子数列都找出来,然后看这些子数列能不能和跟它相邻的升序的子数列连接起来。

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = +;
typedef __int64 INT;
INT que[maxn];
struct node
{
int f,r,l;
}da[maxn]; int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i = ;i < n;++i)
scanf("%I64d",&que[i]);
INT f = ,temp = que[],s = ;
que[n] = -0x7ffffffff;
for(int i = ;i < n;++i)
if(que[i] >= que[i + ])
{
da[f].f = s;
da[f].r = i;
da[f].l = da[f].r - da[f].f + ;
s = i+;
f++;
}
// for(int i = 0;i < f;++i)
// printf("%d %d %d\n",da[i].f,da[i].r,da[i].l);
int ans = ;
for(int i = ;i < f - ;++i)
{
ans = max(ans,da[i].l);
if(f > )
ans = max(ans,da[i].l + );
if(da[i].l > && que[da[i].r - ] < que[da[i+].f] - )
ans = max(ans,da[i].l + da[i+].l);
if(da[i+].l > && que[da[i].r] < que[da[i+].f + ] - )
ans = max(ans,da[i].l + da[i+].l);
}
if(f == )
ans = da[].l;
if(f > )
ans = max(ans,da[f-].l+);
printf("%d\n",ans);
}
return ;
}

Codeforces Round #FF (Div. 2) C. DZY Loves Sequences的更多相关文章

  1. 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] + ...

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

  3. Codeforces Round #FF (Div. 1) A. DZY Loves Sequences

    题目链接: http://www.codeforces.com/contest/446/problem/A 题解: dp1[x]表示以x结尾的最大严格升序连续串,dp2[x]表示以x开头的最大严格升序 ...

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

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

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

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

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

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

随机推荐

  1. css圆角矩形及去掉空格属性

    css圆角矩形 -webkit-border-radius:5px; -moz-border-radius:5px; border-radius:5px; 去掉空格 white-space:nowra ...

  2. 团队作业--Beta版本冲刺

    项目冲刺随笔 第一天 第二天 第三天 第四天 第五天 第六天 第七天

  3. Easyui使用记录

    一天就这搞了这几行. 1. if else 可以嵌套: 2. 子页面调用父页面js,需要使用top.父页面js的方法. <script type="text/javascript&qu ...

  4. The first gui program by Qt

    #include<QApplication> #include<QPushButton> int main(int argc, char **argv) {     QAppl ...

  5. 视频播放用户行为记录之使用Cache的方法

    在上一篇文章http://www.cnblogs.com/ryuasuka/p/3483632.html中,为了获取视频播放时的用户行为,并且要异步地将其写入XML文件中,我采用了先写入log,后生成 ...

  6. 【HDU 1009】FatMouse' Trade

    题 Description FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the ware ...

  7. webservice配置

    服务端配置:第一步:引用jar包commons-httpclient.jarcommons-logging.jarjdom-10.jarwsdl4j-1.6.1.jarxbean-spring-2.8 ...

  8. BZOJ-1951 古代猪文 (组合数取模Lucas+中国剩余定理+拓展欧几里得+快速幂)

    数论神题了吧算是 1951: [Sdoi2010]古代猪文 Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1573 Solved: 650 [Submit ...

  9. NOI2002 洛谷 P1196 银河英雄传说

    神奇的并查集问题 题目描述 公元五八○一年,地球居民迁移至金牛座α第二行星,在那里发表银河联邦 创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展. 宇宙历七九九年,银河系的两大军事集团在巴米利恩 ...

  10. PHP Simulation HTTP Request(undone)

    目录 . 引言 . file_get_contents版本 . Socket版本 . Curl版本 . Curl版本() . 模拟文件上传 0. 引言 本文总结了通过PHP代码方式模拟各种HTTP请求 ...