当前位置:网站首页>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;
}边栏推荐
- Luogu deep foundation part 1 Introduction to language Chapter 6 string and file operation
- Decompile and modify the non source exe or DLL with dnspy
- How PHP drives mongodb
- (POJ - 2912) rochambau (weighted concurrent search + enumeration)
- Functions and differences between static and Const
- Dahua series books
- gslb(global server load balance)技術的一點理解
- 2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions
- regular expression
- Control loop of program (while loop)
猜你喜欢

Exness: the Central Bank of England will raise interest rates again in March, and inflation is coming

Minio deployment

Teach you how to install aidlux (1 installation)

Compréhension de la technologie gslb (Global Server load balance)

Collections SQL communes

QFileDialog

Kali2021.4a build PWN environment

Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?

MySQL - idea connects to MySQL

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.
随机推荐
js demo 計算本年度還剩下多少天
Cesium terrain clipping draw polygon clipping
Asynchronous artifact: implementation principle and usage scenario of completable future
Redis concludes that the second pipeline publishes / subscribes to bloom filter redis as a database and caches RDB AOF redis configuration files
JS closure knowledge points essence
The 14th five year plan for the construction of Chinese Enterprise Universities and the feasibility study report on investment Ⓓ 2022 ~ 2028
What is the content of the securities practice examination?
Introduction to kubernetes
Team collaborative combat penetration tool CS artifact cobalt strike
WFC900M-Network_ Card/Qualcomm-Atheros-AR9582-2T-2R-MIMO-802.11-N-900M-high-power-Mini-PCIe-Wi-Fi-Mod
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
The White House held an open source security summit, attended by many technology giants
Control loop of program (while loop)
Capturing and sorting out external articles -- autoresponder, composer, statistics [III]
How to obtain opensea data through opensea JS
Dynamic research and future planning analysis report of China's urban water supply industry Ⓝ 2022 ~ 2028
JS demo calculate how many days are left in this year
UC Berkeley proposes a multitask framework slip
(5) User login - services and processes - History Du touch date stat CP
Morning flowers and evening flowers