Codeforces Round #605 (Div. 3) D. Remove One Element(DP)
2024-09-06 20:22:33
链接:
https://codeforces.com/contest/1272/problem/D
题意:
You are given an array a consisting of n integers.
You can remove at most one element from this array. Thus, the final length of the array is n−1 or n.
Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array.
Recall that the contiguous subarray a with indices from l to r is a[l…r]=al,al+1,…,ar. The subarray a[l…r] is called strictly increasing if al<al+1<⋯<ar.
思路:
正着反着算一边,能往两边延长的最大长度,对每个点特判。
代码:
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+10;
int Dp[MAXN], a[MAXN], Dpr[MAXN];
int n;
int main()
{
cin >> n;
for (int i = 1;i <= n;++i)
cin >> a[i];
int ans = 1;
Dp[0] = Dpr[n+1] = 0;
Dp[1] = Dpr[n] = 1;
for (int i = 2;i <= n;++i)
{
if (a[i] > a[i-1])
Dp[i] = Dp[i-1]+1;
else
Dp[i] = 1;
}
for (int i = n-1;i >= 1;--i)
{
if (a[i] < a[i+1])
Dpr[i] = Dpr[i+1]+1;
else
Dpr[i] = 1;
}
for (int i = 2;i <= n;++i)
{
ans = max(ans, Dp[i]);
if (a[i] > a[i-2])
ans = max(ans, Dp[i-2]+Dpr[i]);
}
cout << ans << endl;
return 0;
}
最新文章
- SpringMVC初始化参数绑定--日期格式
- codefordream 关于js初级训练
- 设置 Unix,Linux环境下的NLS_LANG
- Jquery开灯关灯效果
- 配置Chrome Driver
- 为什么需要Bundler
- 从逆向的角度去理解C++虚函数表
- Swift中的数组
- mysql的小知识点(关于数据库的导入导出 对于windows)
- org.pentaho.di.ui.core.widget.PasswordTextVar
- C# 中的sealed修饰符学习
- TabHost理解与使用
- css属性之vertical-align详解
- 1、发布C++实现的TCP网络框架Khala
- UIStepper UISlider UISwitch UITextField 基本控件
- 洛谷-哥德巴赫猜想(升级版)-BOSS战-入门综合练习1
- C++基础知识1
- css学习の第三弹—盒模型的创建和使用
- mac下利用Breakpad的dump文件进行调试
- [bzoj1063][Noi2008]道路设计