当前位置:网站首页>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;
}边栏推荐
- Preliminary analysis of smart microwave radar module
- Mindmanager2022 serial number key decompression installer tutorial
- Market layout planning and latest dynamic analysis report of China's smart public security industry Ⓕ 2022 ~ 2028
- A little understanding of GSLB (global server load balance) technology
- [secretly kill little partner pytorch20 days] - [day3] - [example of text data modeling process]
- [sg function] 2021 Niuke winter vacation training camp 6 h. winter messenger 2
- Are the top ten securities companies safe to open accounts and register? Is there any risk?
- Kali2021.4a build PWN environment
- Dahua series books
- Idea shortcut word operation
猜你喜欢

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

90 後,辭職創業,說要卷死雲數據庫
Implementation principle of inheritance, encapsulation and polymorphism

Blue Bridge Cup Guoxin Changtian single chip microcomputer -- led lamp module (V)

How PHP gets all method names of objects

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

Dahua series books

treevalue——Master Nested Data Like Tensor

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

MySQL——JDBC
随机推荐
2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions
Correlation
常用sql集合
JS notes (III)
Is the account opening of Guotai Junan Securities safe and reliable? How to open Guotai Junan Securities Account
Yyds dry inventory Chapter 4 of getting started with MySQL: data types that can be stored in the data table
How PHP adds two numbers
Miscellaneous things that don't miss the right business
MySQL - idea connects to MySQL
QGIS grid processing DEM data reclassification
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)
Netfilter ARP log
Décompiler et modifier un exe ou une DLL non source en utilisant dnspy
Report on the current situation and development trend of ethoxylated sodium alkyl sulfate industry in the world and China Ⓞ 2022 ~ 2027
[SRS] build a specified version of SRS
Blue Bridge Cup Guoxin Changtian single chip microcomputer -- software environment (II)
Investment analysis and prospect trend prediction report of China's boron nitride industry Ⓨ 2022 ~ 2028
Let me ask you a question. Have you ever used the asynchronous io of Flink SQL to associate dimension tables in MySQL? I set various settings according to the official website
Go language slice interview real question 7 consecutive questions
Compréhension de la technologie gslb (Global Server load balance)