codeforces#FF(div2) DZY Loves Sequences
来源:互联网 发布:轩辕剑之苍之涛mac 编辑:程序博客网 时间:2024/06/05 09:45
n个数,可以任意改变其中一个数,求最长的上升子区间长度
思路:记录一个from[i]表示从位置i的数开始最长的上升区间长度
记录一个to[i]表示到位置i的数所能达到的最长上升区间长度
枚举要改变的数的位置i,此时能达到的长度为to[i - 1] + from[i + 1] + 1,取最大值
//#pragma comment(linker, "/STACK:102400000,102400000")//HEAD#include <cstdio>#include <cstring>#include <vector>#include <iostream>#include <algorithm>#include <queue>#include <string>#include <set>#include <stack>#include <map>#include <cmath>#include <cstdlib>using namespace std;//LOOP#define FE(i, a, b) for(int i = (a); i <= (b); ++i)#define FED(i, b, a) for(int i = (b); i>= (a); --i)#define REP(i, N) for(int i = 0; i < (N); ++i)#define CLR(A,value) memset(A,value,sizeof(A))//STL#define PB push_back//INPUT#define RI(n) scanf("%d", &n)#define RII(n, m) scanf("%d%d", &n, &m)#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)#define RS(s) scanf("%s", s)typedef long long LL;const int INF = 0x3f3f3f3f;const int MAXN = 1010;#define FF(i, a, b) for(int i = (a); i < (b); ++i)#define FD(i, b, a) for(int i = (b) - 1; i >= (a); --i)#define CPY(a, b) memcpy(a, b, sizeof(a))#define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)#define EQ(a, b) (fabs((a) - (b)) <= 1e-10)#define ALL(c) (c).begin(), (c).end()#define SZ(V) (int)V.size()#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)#define WI(n) printf("%d\n", n)#define WS(s) printf("%s\n", s)typedef vector <int> VI;typedef unsigned long long ULL;const double eps = 1e-10;const LL MOD = 1e9 + 7;int a[100010];int to[100010], from[100010];int main(){ //freopen("0.txt", "r", stdin); int n; while (~RI(n)) { FE(i, 1, n) RI(a[i]), to[i] = from[i] = 1; FE(i, 2, n) if (a[i] > a[i - 1]) to[i] = to[i - 1] + 1; FED(i, n - 1, 1) if (a[i + 1] > a[i]) from[i] = from[i + 1] + 1;// FE(i, 1, n)// cout << to[i] <<' ';;cout << endl;// FE(i, 1, n)// cout << from[i] <<' ' ; cout << endl; int ans = 1; if (n > 1) ans = max(from[2] + 1, to[n - 1] + 1); FE(i, 2, n - 1) { if (a[i + 1] - a[i - 1] >= 2) { if (to[i - 1] + from[i + 1] + 1 > ans) { ans = to[i - 1] + from[i + 1] + 1;// cout << i <<endl; } } else { ans = max(ans, to[i - 1] +1); ans = max(ans, from[i + 1] + 1); } } cout << ans << endl; } return 0;}
10 0
- codeforces#FF(div2) DZY Loves Sequences
- codeforces#FF(div2) D DZY Loves Modification
- Codeforces Round #FF (Div. 2):C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2) Problem C DZY Loves Sequences
- Codeforces Round #FF (Div. 2)C - DZY Loves Sequences
- Codeforces Round #FF (Div. 2)-C. DZY Loves Sequences
- Codeforces Round #FF 446A DZY Loves Sequences
- Codeforces Round #FF (Div. 2)C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2) C. DZY Loves Sequences
- codeforces#FF DIV2C题DZY Loves Sequences(DP)
- Codeforces Round #FF (Div. 二):C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2) C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2) C DZY Loves Sequences
- Codeforces Round #FF (Div. 2)C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2)C. DZY Loves Sequences
- codeforces#FF DIV2C题DZY Loves Sequences(DP)
- Codeforces Round #FF (Div. 2)-C. DZY Loves Sequences
- Codeforces Round #FF (Div. 2) C. DZY Loves Sequences
- Qt编程20:QPixmap,QImage,QBitmap的简单使用
- TF-IDF与余弦相似性的应用(三):自动摘要
- freemarker 模板中定义变量
- redshift 学习总结
- ORACLE 通配符
- codeforces#FF(div2) DZY Loves Sequences
- Codeforces Round #FF (Div. 2)-C. DZY Loves Sequences
- 现象:ListView拖动时,背景颜色会变成黑色
- 2014年央视广告 世纪盘古《夕阳红》央视广告价格
- sqlstr连接sqlsever
- crm使用url打开窗体视图
- Java 虚拟机的自适应动态优化
- Codeforces Round #FF (Div.2 )(C,D)
- 全自动自清洗过滤器功能及特点