当前位置:网站首页>[7.21-26] code source - [sports festival] [Dan fishing war] [maximum weight division]
[7.21-26] code source - [sports festival] [Dan fishing war] [maximum weight division]
2022-07-29 01:49:00 【ZhgDgE】
#668. Sports Festival
The question : Given sequence , You need to rearrange the sequence , Make the sum of the prefix extreme value difference of the sequence minimum , Output this minimum value . ( n ≤ 2000 ) (n\leq 2000) (n≤2000)
Answer key :( Section dp) Code source daily question Div1 Sports Festival
Ideas : Let's think about it , Now there is a good sequence , We insert an element that will become the extreme value of the sequence , So where does it contribute the least ? Put it last . Because if you put it in the middle , It will affect the extreme value difference of the following prefix . For elements that do not become extreme values of the sequence , We don't consider the insertion strategy .
Then let's arrange the order , Expand outward from each point , The extension must be the extreme point . Definition d p ( i , j ) dp(i,j) dp(i,j) As interval [ i , j ] [i,j] [i,j] Minimum prefix extremum difference sum , Adopt outward expansion interval 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))
Some intervals DP The topic ( Enumerate breakpoints , And interval merging ): Section dp
AC Code :http://oj.daimayuan.top/submission/299976
#702. Dan fishing war
The question : ( n , q ≤ 5 × 1 0 5 ) (n,q\leq 5\times 10^5) (n,q≤5×105)

Answer key :( Monotonic stack / Tree array ) Code source daily question Div1 Dan fishing war
Ideas : Because an element is good if and only if there is only one element in the stack after scanning . So let's simulate , Then the stack is processed and swept to each element , The subscript of the secondary element at the top of the stack . Now give us an interval , If we want an element to be good , Then we hope that this sub element is not in this interval , Then all the following elements will not appear , This element is good .
After preprocessing the sub element subscript of each element , The problem is transformed into an interval to find how many numbers are less than the given number , Classic offline tree array problem .
AC Code :http://oj.daimayuan.top/submission/301595
#709. Maximum weight division
The question : For a sequence , Define the weight of this sequence as the range of this sequence , That is, the difference between the maximum value and the minimum value of the sequence . Given a sequence a a a , You can divide it into any continuous sequence , Find the maximum value of the weight sum of each segment . ( n ≤ 1 0 6 ) (n\leq 10^6) (n≤106)
Answer key :(DP) Code source daily question Div1 Maximum weight division
Ideas : First of all, it is easy to think of dividing the sequence greedily into LIS and LDS Calculation , However, it's easy wa. We can DP, Definition d p ( i ) dp(i) dp(i) Before presentation i i i The maximum number of , However, it is found that the transfer is located in LIS or LDS Relevant , So open another dimension to distinguish . Definition d p ( i , j ) dp(i,j) dp(i,j) Before presentation i i i The maximum number of , And when j = 0 / 1 j=0/1 j=0/1 Express a i a_i ai In descent / Ascending sequence .
边栏推荐
- How to protect WordPress website from network attack? It is essential to take safety measures
- 动态内存与智能指针
- StoneDB 为何敢称业界唯一开源的 MySQL 原生 HTAP 数据库?
- Cross modal alignment 20220728
- 【Unity项目实践】合成大西瓜
- Google Cloud Spanner的实践经验
- Where will Jinan win in hosting the first computing power conference?
- [hcip] two mGRE networks are interconnected through OSPF (ENSP)
- JVM learning minutes
- [unity project practice] synthetic watermelon
猜你喜欢

Behind the second round of okaleido tiger sales is the strategic support of ecological institutions

Event express | Apache Doris Performance Optimization Practice Series live broadcast course is open at the beginning. You are cordially invited to participate!

SQL question brushing: find the last of all employees who have been assigned departments_ Name and first_ Name and Dept_ no

Reinforcement learning (III): dqn, nature dqn, double dqn, with source code interpretation

【Unity项目实践】合成大西瓜

10 major network security incidents in the past 10 years

StoneDB 邀请您参与开源社区月会!
![[search] - DFS pruning and optimization](/img/d4/7c2fec02f5a6bcfa2d5e204398af01.png)
[search] - DFS pruning and optimization

Analyze OP based on autoware_ global_ Planner global path planning module re planning

LeetCode 112:路径总和
随机推荐
With the explosive growth of digital identity in 2022, global organizations are facing greater network security
Comprehensive upgrade, all you can imagine is here -- JD API interface
Pinduoduo can use many API interfaces
[hcip] MPLS Foundation
秘术冬潮烙技能搭配
J9 number theory: what factors determine the value of NFT?
承办首届算力大会,济南胜在何处?
In depth analysis of C language memory alignment
【Web技术】1395- Esbuild Bundler HMR
After understanding the composition of the URL of the website, we use the URL module, querystring module and mime module to improve the static website
如何选择专业、安全、高性能的远程控制软件
[observation] ranked first in SaaS of pure public cloud in three years, and yonsuite's "flywheel effect"
[网鼎杯 2020 朱雀组]Nmap
【7.21-26】代码源 - 【体育节】【丹钓战】【最大权值划分】
CSDN modify column name
Behind the second round of okaleido tiger sales is the strategic support of ecological institutions
Sigma-DSP-OUTPUT
Analyzing the function of human-computer interface module of runtime manager based on autoware
规划数学期末考试模拟二
10 major network security incidents in the past 10 years