当前位置:网站首页>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;
}
边栏推荐
- [SRS] build a specified version of SRS
- UC Berkeley proposes a multitask framework slip
- Global and Chinese market of wireless hard disk 2022-2028: Research Report on technology, participants, trends, market size and share
- Miscellaneous things that don't miss the right business
- Mysql database - Advanced SQL statement (I)
- Are the top ten securities companies safe to open accounts and register? Is there any risk?
- What is the content of the securities practice examination?
- Après 90 ans, j'ai démissionné pour démarrer une entreprise et j'ai dit que j'allais détruire la base de données Cloud.
- What is the difference between res.send() and res.end() in the node express framework
- Rest参考
猜你喜欢
treevalue——Master Nested Data Like Tensor
常用sql集合
The post-90s resigned and started a business, saying they would kill cloud database
Preliminary analysis of smart microwave radar module
6.0 kernel driver character driver
2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions
Blue Bridge Cup Guoxin Changtian single chip microcomputer -- led lamp module (V)
QGIS grid processing DEM data reclassification
Functions and differences between static and Const
MySQL——JDBC
随机推荐
Cognitive fallacy: what is Fredkin's paradox
Tkinter Huarong Road 4x4 tutorial III
Report on the development status and investment planning trends of China's data center industry Ⓡ 2022 ~ 2028
Minio deployment
Is it safe and reliable to open an account and register for stock speculation? Is there any risk?
2022 G3 boiler water treatment registration examination and G3 boiler water treatment examination papers
内存分析器 (MAT)
Common SQL sets
Idea shortcut word operation
A little understanding of GSLB (global server load balance) technology
What is the content of the securities practice examination?
油猴插件
The post-90s resigned and started a business, saying they would kill cloud database
How PHP adds two numbers
Collection | pytoch common loss function disassembly
Decompile and modify the non source exe or DLL with dnspy
JS notes (III)
Dynamic research and future planning analysis report of China's urban water supply industry Ⓝ 2022 ~ 2028
[sg function] 2021 Niuke winter vacation training camp 6 h. winter messenger 2
[sg function]split game (2020 Jiangxi university student programming competition)