当前位置:网站首页>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;
}边栏推荐
- The 14th five year plan for the construction of Chinese Enterprise Universities and the feasibility study report on investment Ⓓ 2022 ~ 2028
- 2022 safety officer-a certificate registration examination and summary of safety officer-a certificate examination
- Cognitive fallacy: Wittgenstein's ruler
- Global and Chinese market of telematics boxes 2022-2028: Research Report on technology, participants, trends, market size and share
- Cesium terrain clipping draw polygon clipping
- How PHP gets all method names of objects
- Base ring tree Cartesian tree
- Implementation principle of inheritance, encapsulation and polymorphism
- pivot ROP Emporium
- 使用dnSpy对无源码EXE或DLL进行反编译并且修改
猜你喜欢

treevalue——Master Nested Data Like Tensor

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

Data consistency between redis and database
![Intimacy communication -- [repair relationship] - use communication to heal injuries](/img/c2/f10405e3caf570dc6bd124d65b2e93.jpg)
Intimacy communication -- [repair relationship] - use communication to heal injuries

How PHP drives mongodb

gslb(global server load balance)技术的一点理解

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

使用dnSpy對無源碼EXE或DLL進行反編譯並且修改
![[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)

常用sql集合
随机推荐
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
On my first day at work, this API timeout optimization put me down!
Yiwen teaches you how to choose your own NFT trading market
Go language slice interview real question 7 consecutive questions
6.0 kernel driver character driver
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
Dahua series books
DR882-Qualcomm-Atheros-QCA9882-2T2R-MIMO-802.11ac-Mini-PCIe-Wi-Fi-Module-5G-high-power
Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy
Team collaborative combat penetration tool CS artifact cobalt strike
Investment analysis and prospect trend prediction report of China's boron nitride industry Ⓨ 2022 ~ 2028
Why use pycharm to run the use case successfully but cannot exit?
Blue Bridge Cup Guoxin Changtian single chip microcomputer -- software environment (II)
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
股票炒股开户注册安全靠谱吗?有没有风险的?
What if the Flink SQL client exits and the table is emptied?
4. Data splitting of Flink real-time project
MySQL - idea connects to MySQL
Development trend and market demand analysis report of China's energy storage battery industry Ⓩ 2022 ~ 2028
2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions