当前位置:网站首页>Codeforces Round #276 (Div. 1) D. Kindergarten
Codeforces Round #276 (Div. 1) D. Kindergarten
2022-08-10 12:56:00 【Snow_raw】
Codeforces Round #276 (Div. 1) D. Kindergarten
题意: in a kindergarten,Children are divided into groups,Each group must be a continuous segment,Each group has a Charisma score,Its value is the difference between the largest value and the smallest value in the group,That is, the group attractiveness value of a group of people 0 0 0 .Ask how to group so that the sum of all groups' charisma can be maximized?
思路: 首先有一个结论,It must be optimal to group the values monotonically increasing or monotonically decreasing.Then the part we need to study is whether the value at the inflection point belongs to the previous group or the next group?我们采用 d p dp dp 的做法,取最优值即可.
代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>PII;
const int N = 1e6+10;
int dp[N];
int a[N];
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int last=1;
int n;
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=2;i<=n;i++){
int x1=dp[last-1]+abs(a[i]-a[last]);
int x2=dp[last]+abs(a[i]-a[last+1]);
dp[i]=max(x1,x2);
if(i<n&&(a[i]-a[i-1])*(a[i+1]-a[i])<=0){
last=i;
}
}
cout<<dp[n]<<endl;
return 0;
}
边栏推荐
- Drive IT Modernization with Low Code
- Can CLIP also do segmentation tasks?The University of Göttingen proposed a model CLIPSeg that uses text and image prompts to perform three segmentation tasks at the same time, draining CLIP capabiliti
- 蚂蚁金服+拼多多+抖音+天猫(技术三面)面经合集助你拿大厂offer
- CodeForces - 628D (数位dp)
- 【论文+代码】PEBAL/Pixel-wise Energy-biased Abstention Learning for Anomaly Segmentation on Complex Urban Driving Scenes(复杂城市驾驶场景异常分割的像素级能量偏置弃权学习)
- A detailed explanation of implementation api embed
- H264 码率控制
- 协程与任务
- [List merge] Combine multiple lists into one list
- 10 款更先进的开源命令行工具
猜你喜欢
国外媒体宣发怎样做才可以把握重点
中科院深圳先进技术院合成所赵国屏院士组2022年招聘启事
你有一份斗破苍穹词库,请查收
Chapter9 : De Novo Molecular Design with Chemical Language Models
LeetCode中等题之搜索二维矩阵
LT8911EXB MIPI CSI/DSI to EDP signal conversion
如何让别人看不懂你的 JS 代码?把你当大佬!
基于PLECS的离网(孤岛)并联逆变器的Droop Control下垂控制仿真
11+ chrome高级调试技巧,学会效率直接提升666%
Keithley DMM7510精准测量超低功耗设备各种运作模式功耗
随机推荐
Nanodlp v2.2/v3.0光固化电路板,机械开关/光电开关/接近开关的接法和系统状态电平设置
es6-promise对象详解
IP地址分类以及网络地址的计算(子网划分、超网划分)[通俗易懂]
The 6th "Blue Hat Cup" National College Student Network Security Skills Competition Semi-Final Part WriteUp
An enhanced dynamic packet buffer management. The core part of the paper
Polygon zkEVM工具——PIL和CIRCOM
Servlet---Solve the problem of Chinese garbled characters in post requests
百度用户产品流批一体的实时数仓实践
【集合】HashSet和ArrayList的查找Contains()时间复杂度
把相亲角搬到海外,不愧是咱爸妈
ASP.NET Core依赖注入系统学习教程:ServiceDescriptor(服务注册描述类型)
47Haproxy集群
22年BATJ大厂必问面试题(复盘):JVM+微服务+多线程+锁+高并发
多线程下自旋锁设计基本思想
11+ chrome高级调试技巧,学会效率直接提升666%
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama
[List merge] Combine multiple lists into one list
面试美团被问到了Redis,搞懂这几个问题,让你轻松吊打面试官
three.js blur glass effect
娄底植物细胞实验室建设基本组成要点