当前位置:网站首页>1068. Consolidation of ring stones (ring, interval DP)
1068. Consolidation of ring stones (ring, interval DP)
2022-07-03 22:08:00 【seez】

analysis : Merging with stones only adds a circular condition
For the ring problem , If you just enumerate breakpoints , Open more one dimension on the basis of stone merging , The time complexity is O(n^4)
A general method can be adopted , Is to convert a ring into a chain
By turning from 1 The expanded link is in n Behind , When enumerating like this, Enumerate with Location 2 Broken chain , Just enumerate With 2 Start , The length is len Chain , You can enumerate n And 1 Adjacent situation
The state transition equation is basically the same as the stone merging , The difference lies in the existence of rings , Cause the loop enumeration to be different
for(int len=1;len<=n;len++)
for(int l=1;l+len-1<=2*n;l++)
{// Due to the simulation of intermediate breakpoints , Connect the disconnected ones to the back of the array , So it is possible to enumerate to 2n
...
}
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=410;
int a[N];
int s[N];
int dp[N][N];
int g[N][N];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i],a[n+i]=a[i];
for(int i=1;i<=2*n;i++) s[i]=s[i-1]+a[i];
memset(dp,0x3f,sizeof dp),memset(g,-0x3f,sizeof g);
for(int len=1;len<=n;len++)
for(int l=1;l+len-1<=2*n;l++)
{
int r=l+len-1;
if(len==1) dp[l][r]=g[l][r]=0;
else
for(int k=l;k<r;k++)
{
dp[l][r]=min(dp[l][r],dp[l][k]+dp[k+1][r]+s[r]-s[l-1]);
g[l][r]=max(g[l][r],g[l][k]+g[k+1][r]+s[r]-s[l-1]);
}
}
int maxv=-0x3f3f3f3f,minv=0x3f3f3f3f;
for(int i=1;i<=n;i++)
minv=min(minv,dp[i][i+n-1]),maxv=max(maxv,g[i][i+n-1]);
cout<<minv<<endl<<maxv<<endl;
return 0;
}边栏推荐
- On my first day at work, this API timeout optimization put me down!
- Is the account opening of Guotai Junan Securities safe and reliable? How to open Guotai Junan Securities Account
- China HDI market production and marketing demand and investment forecast analysis report Ⓢ 2022 ~ 2028
- Mysql database - Advanced SQL statement (I)
- The 14th five year plan for the construction of Chinese Enterprise Universities and the feasibility study report on investment Ⓓ 2022 ~ 2028
- DR882-Qualcomm-Atheros-QCA9882-2T2R-MIMO-802.11ac-Mini-PCIe-Wi-Fi-Module-5G-high-power
- What should the future of the Internet be like when Silicon Valley employees flee the big factory and rush to Web3| Footprint Analytics
- Station B, dark horse programmer, employee management system, access conflict related (there is an unhandled exception at 0x00007ff633a4c54d (in employee management system.Exe): 0xc0000005: read locat
- Decompile and modify the non source exe or DLL with dnspy
- What if the Flink SQL client exits and the table is emptied?
猜你喜欢

What is the difference between res.send() and res.end() in the node express framework

Awk getting started to proficient series - awk quick start

2022 G3 boiler water treatment registration examination and G3 boiler water treatment examination papers

Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy

No more! Technical team members resign collectively

(5) User login - services and processes - History Du touch date stat CP

gslb(global server load balance)技術的一點理解

Blue Bridge Cup Guoxin Changtian single chip microcomputer -- software environment (II)

Morning flowers and evening flowers

Bluebridge cup Guoxin Changtian single chip microcomputer -- detailed explanation of schematic diagram (IV)
随机推荐
Data consistency between redis and database
Uboot migration
[sg function] 2021 Niuke winter vacation training camp 6 h. winter messenger 2
油猴插件
2022 safety officer-a certificate registration examination and summary of safety officer-a certificate examination
Awk getting started to proficient series - awk quick start
treevalue——Master Nested Data Like Tensor
Rest reference
Getting started with DOM
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
Supply and demand situation and market scale calculation report of China's portable energy storage power PES industry Ⓛ 2022 ~ 2028
pivot ROP Emporium
2022 free examination questions for safety management personnel of hazardous chemical business units and reexamination examination for safety management personnel of hazardous chemical business units
Common SQL sets
Some 5000+ likes, the development notes of a director of cosmic factory, leaked
Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy
Implementation principle of inheritance, encapsulation and polymorphism
How to store null value on the disk of yyds dry inventory?
Morning flowers and evening flowers
What indicators should be paid attention to in current limit monitoring?