当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
What are the five common data types of Redis?What is the corresponding data storage space?Take you to learn from scratch

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

Data Analysis of Time Series (5): Simple Prediction Method

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

MySQL面试题——MySQL常见查询

阿里云贾朝辉:云XR平台支持彼真科技呈现国风科幻虚拟演唱会

培训机构学习费用是多少呢?

es6-promise对象详解

LeetCode简单题之合并相似的物品

“68道 Redis+168道 MySQL”精品面试题(带解析)
随机推荐
Threshold-based filtering buffer management scheme in a shared buffer packet switch core part of the paper
leetcode/两个链表的第一个重合节点
Common examples of regular expressions
【list合并】多个list合并为一个list
Microchip launched a high-performance 77GHz millimeter-wave radar chip, and has received tens of thousands of orders before mass production
LeetCode 61. Rotating linked list
three.js blur glass effect
Solve the idea that unit tests cannot use Scanner
LT8911EXB MIPI CSI/DSI to EDP signal conversion
没有接班人,格力只剩“明珠精选”
What are the five common data types of Redis?What is the corresponding data storage space?Take you to learn from scratch
国外媒体宣发怎样做才可以把握重点
A detailed explanation of implementation api embed
H264 GOP 扫盲
“68道 Redis+168道 MySQL”精品面试题(带解析)
多线程下自旋锁设计基本思想
LeetCode中等题之颠倒字符串中的单词
StarRocks on AWS Review | Data Everywhere Series Event Shenzhen Station ended successfully
47Haproxy Cluster
日记16