当前位置:网站首页>320. Energy Necklace (ring, interval DP)
320. Energy Necklace (ring, interval DP)
2022-07-03 22:08:00 【seez】

320. Energy necklace - AcWing Question bank
analysis : It can be regarded as a circular interval dp problem
Altogether 4 A bead , There are four marks as shown in the figure , It can be merged to the end, leaving only 2 A sign , That is to say 1 A bead .
Then at least it needs 3 Tags can continue to merge , If it is less than three tags, there is no need to merge .

State means : All consolidation i~j A collection of tags
State calculation / Basis of division : according to i~j The marks in the middle can be divided into those that are neither heavy nor missing j-i-1 A collection of , because i,j It means the mark , Therefore, you cannot participate in the merger (dp[i][i] Not a bead , Do not participate in the operation , therefore dp[i][j],j>=i+1)
The recurrence formula is dp[i][k]+dp[k][j], Because the set before the breakpoint k As a tail mark , The latter set k As a header mark
- i+1 As a breakpoint , Merge dp[i][i+1],dp[i+1][j],dp[i][j]=dp[i][i+1]+dp[i+1][j]+w[i]*w[i+1]*w[j]
- ...
- j-1 As a breakpoint , Merge dp[i][j-1],dp[j-1][j],dp[i][j]=dp[i][j-1]+dp[j-1][j]+w[i]*w[j-1]*w[j]
Initialization and boundary are 0
Recursive method :
for(int len=1;len<=n+1;len++)// Because the right endpoint may be the starting point , therefore <=n+1
// Because the tail mark of the last bead is the first mark
for(int i=1;i+len-1<=2*n;i++)
{
...
}ac Code
#include <iostream>
#include <algorithm>
using namespace std;
const int N=205;
const int INF=0x3f3f3f3f;
int a[N];
int s[N];
int dp[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 len=1;len<=n+1;len++)
for(int i=1;i+len-1<=2*n;i++)
{
int j=i+len-1;
for(int k=i+1;k<j;k++)
dp[i][j]=max(dp[i][j],dp[i][k]+dp[k][j]+a[i]*a[k]*a[j]);
}
int res=0;
for(int i=1;i<=n;i++)
res=max(res,dp[i][i+n]);
cout<<res;
}边栏推荐
- China HDI market production and marketing demand and investment forecast analysis report Ⓢ 2022 ~ 2028
- 常用sql集合
- Getting started with DOM
- 油猴插件
- 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
- How does sentinel, a traffic management artifact, make it easy for business parties to access?
- Is the account opening of Guotai Junan Securities safe and reliable? How to open Guotai Junan Securities Account
- Luogu deep foundation part 1 Introduction to language Chapter 7 functions and structures
- regular expression
- Go language slice interview real question 7 consecutive questions
猜你喜欢

UC Berkeley proposes a multitask framework slip

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

常用sql集合

The latest analysis of crane driver (limited to bridge crane) in 2022 and the test questions and analysis of crane driver (limited to bridge crane)

Cesium terrain clipping draw polygon clipping

Tidb's initial experience of ticdc6.0

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

Yiwen teaches you how to choose your own NFT trading market

This time, thoroughly understand bidirectional data binding 01

Bluebridge cup Guoxin Changtian single chip microcomputer -- detailed explanation of schematic diagram (IV)
随机推荐
Preliminary understanding of C program design
Analysis report on the development trend and Prospect of global and Chinese supercontinuum laser source industry Ⓚ 2022 ~ 2027
Yyds dry inventory Chapter 4 of getting started with MySQL: data types that can be stored in the data table
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
The White House held an open source security summit, attended by many technology giants
regular expression
DR-AP40X9-A-Qualcomm-IPQ-4019-IPQ-4029-5G-4G-LTE-aluminum-body-dual-band-wifi-router-2.4GHZ-5GHz-QSD
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
Remember the experience of automatically jumping to spinach station when the home page was tampered with
2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions
[actual combat record] record the whole process of the server being attacked (redis vulnerability)
Covariance
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy
Rest参考
90 後,辭職創業,說要卷死雲數據庫
Capturing and sorting out external articles -- autoresponder, composer, statistics [III]
Cognitive fallacy: Wittgenstein's ruler
Uboot migration
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.