当前位置:网站首页>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;
}边栏推荐
- Yiwen teaches you how to choose your own NFT trading market
- 使用dnSpy对无源码EXE或DLL进行反编译并且修改
- [secretly kill little partner pytorch20 days] - [day3] - [example of text data modeling process]
- Tidb's initial experience of ticdc6.0
- Morning flowers and evening flowers
- Dahua series books
- [sg function] 2021 Niuke winter vacation training camp 6 h. winter messenger 2
- Global and Chinese market of recycled yarn 2022-2028: Research Report on technology, participants, trends, market size and share
- 仿网易云音乐小程序
- China's TPMS industry demand forecast and future development trend analysis report Ⓐ 2022 ~ 2028
猜你喜欢

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

2022 G3 boiler water treatment registration examination and G3 boiler water treatment examination papers

常用sql集合

Blue Bridge Cup Guoxin Changtian single chip microcomputer -- software environment (II)

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.

Blue Bridge Cup Guoxin Changtian MCU -- program download (III)

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

Morning flowers and evening flowers

Functions and differences between static and Const

Collections SQL communes
随机推荐
JS Demo calcule combien de jours il reste de l'année
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
Kali2021.4a build PWN environment
使用dnSpy對無源碼EXE或DLL進行反編譯並且修改
Yiwen teaches you how to choose your own NFT trading market
English topic assignment (28)
鹏城杯 WEB_WP
On my first day at work, this API timeout optimization put me down!
(5) User login - services and processes - History Du touch date stat CP
What should the future of the Internet be like when Silicon Valley employees flee the big factory and rush to Web3| Footprint Analytics
Redis single thread and multi thread
常用sql集合
使用dnSpy对无源码EXE或DLL进行反编译并且修改
Report on the development strategy of China's engineering bidding agency and suggestions for the 14th five year plan Ⓙ 2022 ~ 2028
Capturing and sorting out external articles -- autoresponder, composer, statistics [III]
Decompile and modify the non source exe or DLL with dnspy
[actual combat record] record the whole process of the server being attacked (redis vulnerability)
油猴插件
JS closure knowledge points essence
Functions and differences between static and Const