当前位置:网站首页>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;
}
边栏推荐
- 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
- Deploy the project halfway through the follow-up
- 47Haproxy集群
- 十八、一起学习Lua 调试(Debug)
- 你有一份斗破苍穹词库,请查收
- Mysql—— 内连接、左连接、右连接以及全连接查询
- 没有接班人,格力只剩“明珠精选”
- So delicious!Since using this interface artifact, my team efficiency has increased by 60%!
- 娄底疾控中心实验室设计理念说明
- iTextSharp 使用详解
猜你喜欢

Chapter 5 virtual memory

Behind IDC's No. 1 position, what kind of "video cloud" is Alibaba Cloud building?

Does face attendance choose face comparison 1:1 or face search 1:N?

如何让别人看不懂你的 JS 代码?把你当大佬!

LT8911EXB MIPI CSI/DSI to EDP signal conversion

So delicious!Since using this interface artifact, my team efficiency has increased by 60%!

【百度统计】用户行为分析

中科院深圳先进技术院合成所赵国屏院士组2022年招聘启事

你是怎么知道数据库 Htap 能力强弱的?怎么能看出来

一文详解 implementation api embed
随机推荐
来看Prada大秀吗?在元宇宙里那种!
2022年8月中国数据库排行榜:openGauss重夺榜眼,PolarDB反超人大金仓
phpstrom 快速注释:
es6-promise对象详解
AICOCO AI Frontier Promotion (8.10)
【数字IC验证进阶】SoC系统验证和IP模块验证的区别及侧重点分析
培训机构学习费用是多少呢?
金山云要飘到哪里?
可视化服务编排在金融APP中的实践
A detailed explanation of implementation api embed
Codeforces Round #276 (Div. 1) B. Maximum Value
Deploy the project halfway through the follow-up
Hackbar 使用教程
Does face attendance choose face comparison 1:1 or face search 1:N?
CodeForces - 628D (digital dp)
48 the mysql database
LeetCode 146. LRU Cache
Alibaba Cloud Jia Zhaohui: Cloud XR platform supports Bizhen Technology to present a virtual concert of national style sci-fi
Threshold-based filtering buffer management scheme in a shared buffer packet switch core part of the paper
iTextSharp操作PDF