当前位置:网站首页>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;
}边栏推荐
- Development mode and Prospect of China's IT training industry strategic planning trend report Ⓣ 2022 ~ 2028
- Investment planning analysis and prospect prediction report of China's satellite application industry during the 14th five year plan Ⓑ 2022 ~ 2028
- 内存分析器 (MAT)
- Global and Chinese market of recycled yarn 2022-2028: Research Report on technology, participants, trends, market size and share
- Dynamic research and future planning analysis report of China's urban water supply industry Ⓝ 2022 ~ 2028
- 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
- Control loop of program (while loop)
- Why use pycharm to run the use case successfully but cannot exit?
- 2022 high altitude installation, maintenance and removal of examination question bank and high altitude installation, maintenance and removal of examination papers
- Dahua series books
猜你喜欢

What should the future of the Internet be like when Silicon Valley employees flee the big factory and rush to Web3| Footprint Analytics
![[secretly kill little partner pytorch20 days] - [day3] - [example of text data modeling process]](/img/55/309c9d52e503405b289bcfc4912be9.jpg)
[secretly kill little partner pytorch20 days] - [day3] - [example of text data modeling process]

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

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

QFileDialog

Introduction to kubernetes

Kali2021.4a build PWN environment
![[dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)](/img/6c/2d48d441fee1981a271319fd9f6c23.jpg)
[dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)

No more! Technical team members resign collectively

How PHP adds two numbers
随机推荐
WFC900M-Network_ Card/Qualcomm-Atheros-AR9582-2T-2R-MIMO-802.11-N-900M-high-power-Mini-PCIe-Wi-Fi-Mod
Nacos common configuration
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
Functions and differences between static and Const
股票炒股开户注册安全靠谱吗?有没有风险的?
Redis concludes that the second pipeline publishes / subscribes to bloom filter redis as a database and caches RDB AOF redis configuration files
[sg function] 2021 Niuke winter vacation training camp 6 h. winter messenger 2
[sg function] lightoj Partitioning Game
6.0 kernel driver character driver
常用sql集合
油猴插件
Yiwen teaches you how to choose your own NFT trading market
Team collaborative combat penetration tool CS artifact cobalt strike
On my first day at work, this API timeout optimization put me down!
Bluebridge cup Guoxin Changtian single chip microcomputer -- detailed explanation of schematic diagram (IV)
This time, thoroughly understand bidirectional data binding 01
Some 5000+ likes, the development notes of a director of cosmic factory, leaked
Decompile and modify the non source exe or DLL with dnspy
Farmersworld farmers world, no faith, how to talk about success?
JS demo calculate how many days are left in this year