当前位置:网站首页>【7.21-26】代码源 - 【体育节】【丹钓战】【最大权值划分】
【7.21-26】代码源 - 【体育节】【丹钓战】【最大权值划分】
2022-07-29 00:53:00 【ZhgDgE】
#668. 体育节
题意:给定序列,你需要重排列序列,使得序列的前缀极值差的和最小,输出这个最小值。 ( n ≤ 2000 ) (n\leq 2000) (n≤2000)
思路:我们思考一下,现在有一个排好的序列,我们插入一个会成为序列极值的元素,那么放在哪里贡献最小?是放在最后。因为如果放在中间,会影响后面前缀的极值差。对于不会成为序列极值的元素,我们不考虑插入策略。
那么我们排一下序,从每个点向外扩展,扩展到的一定是极值点。定义 d p ( i , j ) dp(i,j) dp(i,j) 为区间 [ i , j ] [i,j] [i,j] 的最小前缀极值差和,采用向外拓展的区间 DP, d p ( i , j ) = a j − a i + max ( d p ( i + 1 , j ) , d p ( i , j − 1 ) ) dp(i,j)=a_j-a_i+\max(dp(i+1,j),dp(i,j-1)) dp(i,j)=aj−ai+max(dp(i+1,j),dp(i,j−1))
一些区间 DP 的题(枚举中断点,以及区间合并):区间dp
AC代码:http://oj.daimayuan.top/submission/299976
#702. 丹钓战
题意: ( n , q ≤ 5 × 1 0 5 ) (n,q\leq 5\times 10^5) (n,q≤5×105)

思路:因为一个元素是好的当且仅当扫描后栈中仅有一个元素。那么我们模拟一下,然后处理出来栈扫到每个元素之后,栈顶的次元素下标。现在给我们一个区间,如果我们希望某个元素是好的,那么我们希望这个次元素没有在这个区间内,那么下面所有的元素都不会出现,这个元素就是好的。
预处理出来每个元素的次元素下标后,问题转化为区间求有多少个数小于给定数,经典离线树状数组问题。
AC代码:http://oj.daimayuan.top/submission/301595
#709. 最大权值划分
题意:对于一段序列,定义这段序列的权值为这段序列的极差,即序列的最大值与最小值之差。给定一个序列 a a a ,你可以将它划分成任意段连续的序列,求出每一段的权值和的最大值。 ( n ≤ 1 0 6 ) (n\leq 10^6) (n≤106)
思路:首先容易想到把序列贪心分块为 LIS 和 LDS 计算,然而很容易 wa。我们可以 DP,定义 d p ( i ) dp(i) dp(i) 表示前 i i i 个数的最大值,然而发现转移是和上个数位于 LIS 或 LDS 有关的,因此再开一维用来区分。定义 d p ( i , j ) dp(i,j) dp(i,j) 表示前 i i i 个数的最大值,且当 j = 0 / 1 j=0/1 j=0/1 表示 a i a_i ai 位于下降 / 上升序列。
边栏推荐
- [hcip] two mGRE networks are interconnected through OSPF (ENSP)
- Making high-precision map based on autoware (V)
- How to deal with the DDoS attack on the game server and how to defend it?
- [机缘参悟-54]:《素书》-1-事物缘起[原始章第一]:大道至简。
- What are source code, inverse code and complement code
- 科研环境对人的影响是很大的
- C language 300 lines of code to achieve mine sweeping (deployable + markable + changeable difficulty level)
- 数据库的decimal类型的数据,发现可以通过resultSet.getDouble去拿到这个数据,但是通过getObject却拿不到这个属性。
- ELS square movement
- 明日无限计划,2022某公司元宇宙产品发布会活动概念策划方案
猜你喜欢

J9数字论:什么因素决定NFT的价值?

采用QT进行OpenGL开发(二)绘制立方体

Autoware reports an error: can't generate global path for start solution

For a safer experience, Microsoft announced the first PC with a secure Pluto chip

Openpyxl library fill color

【Web技术】1395- Esbuild Bundler HMR
![[hcip] MPLS Foundation](/img/91/a2aebf333fb3e3fedf0fc393e175a9.png)
[hcip] MPLS Foundation
![[observation] ranked first in SaaS of pure public cloud in three years, and yonsuite's](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[observation] ranked first in SaaS of pure public cloud in three years, and yonsuite's "flywheel effect"

What are source code, inverse code and complement code

560 和为 K 的子数组
随机推荐
【观察】三年跃居纯公有云SaaS第一,用友YonSuite的“飞轮效应”
els 方块移动
How to deal with the DDoS attack on the game server and how to defend it?
数据库的decimal类型的数据,发现可以通过resultSet.getDouble去拿到这个数据,但是通过getObject却拿不到这个属性。
代码生成器
过去10年的10起重大网络安全事件
[hcip] experiment of republishing and routing strategy
[understanding of opportunity-54]: plain book-1-the origin of things [original chapter 1]: the road is simple.
Django uses pymysql module to connect mysql database
剑指offer专项突击版第13天
5G 商用第三年:无人驾驶的“上山”与“下海”
【HCIP】MPLS 基础
It is found that the data of decimal type in the database can be obtained through resultset.getdouble, but this attribute cannot be obtained through GetObject.
C语言犄角旮旯的知识之形参、实参、main函数参数、数组或指针做函数参数等
【GoLang】网络连接 net.Dial
Window object of BOM series
Timer of BOM series
[search] - DFS pruning and optimization
Redis installation, cluster deployment and common tuning
【golang】使用select {}