当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

2022年8月中国数据库排行榜:openGauss重夺榜眼,PolarDB反超人大金仓
MySQL索引的B+树到底有多高?

人脸考勤是选择人脸比对1:1还是人脸搜索1:N?

Keithley DMM7510精准测量超低功耗设备各种运作模式功耗

CURRENT_TIMESTAMP(6) 函数是否存在问题?

LeetCode中等题之颠倒字符串中的单词

爱可可AI前沿推介(8.10)

dedecms supports one-click import of Word content

Solve the idea that unit tests cannot use Scanner

Crypto Gaming: The Future of Gaming
随机推荐
You have a Doubaqiong thesaurus, please check it
ArcMAP出现-15的问题无法访问[Provide your license server administrator with the following information:Err-15]
动态规划之最长回文子串
【黑马早报】雷军称低谷期曾想转行开酒吧;拜登正式签署芯片法案;软银二季度巨亏230亿美元;北京市消协约谈每日优鲜...
基础 | batchnorm原理及代码详解
线代 | 秒杀方法与技巧
dedecms supports one-click import of Word content
Digicert EV证书签名后出现“证书对于请求用法无效”的解决方案
So delicious!Since using this interface artifact, my team efficiency has increased by 60%!
Accumulated and thin hair!Safety Dog has once again obtained the certification of scientific and technological achievements transformation!
CV复习:空洞卷积
毕业总结
阿里云贾朝辉:云XR平台支持彼真科技呈现国风科幻虚拟演唱会
Mysql—— 内连接、左连接、右连接以及全连接查询
Drive IT Modernization with Low Code
漏洞管理计划的未来趋势
LeetCode简单题之合并相似的物品
LeetCode 237. Delete a node in a linked list
iTextSharp 使用详解
虚拟机桥接模式不能上网