当前位置:网站首页>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;
}边栏推荐
- [secretly kill little partner pytorch20 days] - [day3] - [example of text data modeling process]
- DOM light switch case
- Introduction to kubernetes
- 4. Data splitting of Flink real-time project
- Supply and demand situation and market scale calculation report of China's portable energy storage power PES industry Ⓛ 2022 ~ 2028
- Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
- Global and Chinese market of wireless hard disk 2022-2028: Research Report on technology, participants, trends, market size and share
- Analysis report on the development trend and Prospect of global and Chinese supercontinuum laser source industry Ⓚ 2022 ~ 2027
- Persistence of Nacos
- Cognitive fallacy: Wittgenstein's ruler
猜你喜欢

2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions

Farmersworld farmers world, no faith, how to talk about success?

On my first day at work, this API timeout optimization put me down!

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

Persistence of Nacos

2022 electrician (elementary) examination questions and electrician (elementary) registration examination

Imitation Netease cloud music applet

Tidb's initial experience of ticdc6.0

How PHP drives mongodb

Why use pycharm to run the use case successfully but cannot exit?
随机推荐
What is the content of the securities practice examination?
The 14th five year plan for the construction of Chinese Enterprise Universities and the feasibility study report on investment Ⓓ 2022 ~ 2028
Idea shortcut word operation
Remember the experience of automatically jumping to spinach station when the home page was tampered with
gslb(global server load balance)技術的一點理解
JS demo calculate how many days are left in this year
Pengcheng cup Web_ WP
Netfilter ARP log
Sed、Awk
(POJ - 2912) rochambau (weighted concurrent search + enumeration)
How PHP adds two numbers
Global and Chinese market of wall mounted kiosks 2022-2028: Research Report on technology, participants, trends, market size and share
内存分析器 (MAT)
油猴插件
Awk getting started to proficient series - awk quick start
Redis single thread and multi thread
Décompiler et modifier un exe ou une DLL non source en utilisant dnspy
WFC900M-Network_ Card/Qualcomm-Atheros-AR9582-2T-2R-MIMO-802.11-N-900M-high-power-Mini-PCIe-Wi-Fi-Mod
DR-AP40X9-A-Qualcomm-IPQ-4019-IPQ-4029-5G-4G-LTE-aluminum-body-dual-band-wifi-router-2.4GHZ-5GHz-QSD
Cesium terrain clipping draw polygon clipping