当前位置:网站首页>Dynamic programming [III] (interval DP) stone merging
Dynamic programming [III] (interval DP) stone merging
2022-06-27 12:02:00 【Wu Yu 4】
Stone merging
link :282. Stone merging - AcWing Question bank
Topic :

Ideas :

Code :
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=310;
int n,a[N],sum[N],f[N][N];
int main()
{
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
// Prefix sum method
for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
// Calculation [l,r] Prefix and formula for :sum[r]-sum[l-1]
// The interval length traverses from small to large
for(int len=2;len<=n;len++)// The length is 1 The time is not to merge , From 2 Start the cycle
{
for(int i=1;i+len-1<=n;i++)
{
int l=i,r=i+len-1;
f[l][r]=1e8;// The minimum value is required here , So the initial value is assigned a larger number
for(int s=l;s<r;s++)// That is, the state transition in the train of thought can be increased from the left to r-1
f[l][r]=min(f[l][r],f[l][s]+f[s+1][r]+sum[r]-sum[l-1]);
}
}
cout<<f[1][n]<<endl;
return 0;
}边栏推荐
- AutoCAD - three pruning methods
- [tcapulusdb knowledge base] tcapulusdb doc acceptance - create business introduction
- 星际争霸的虫王IA退役2年搞AI,自叹不如了
- In depth analysis of error solutions and problems in dynamic loading of unity shadow and outline components
- 【On nacos】快速上手 Nacos
- Nvme2.0 protocol - new features
- Detailed explanation of interprocess communication
- Youboxun attended the openharmony technology day to create a new generation of secure payment terminals
- AUTOCAD——三种修剪方式
- matlab习题 —— 创建 50 行 50 列全零矩阵、全 1 矩阵、单位矩阵、对角矩阵,输出矩阵第135号元素。
猜你喜欢

In 2021, the global carbon graphite brush revenue is about US $2366million, and it is expected to reach US $2701.8 million in 2028

In 2021, the global professional liability insurance revenue was about USD 44740million, and it is expected to reach USD 55980million in 2028. From 2022 to 2028, the CAGR was 3.5%

MapReduce practical cases (customized sorting, secondary sorting, grouping, zoning)

Build the Internet of things system from scratch

15+ urban road element segmentation application, this segmentation model is enough!

1. Mx6ull startup mode

MapReduce principle analysis (in-depth source code)

Youboxun attended the openharmony technology day to create a new generation of secure payment terminals

优博讯出席OpenHarmony技术日,全新打造下一代安全支付终端

【On nacos】快速上手 Nacos
随机推荐
Jerry's DAC output mode setting [chapter]
怎么找相同台词的影视片段?这8个电影搜索神器,一句台词找到对应片段
C語言0長度數組的妙用
c/s 架构
Interviewer: with the for loop, why do you need foreach?
【面试高频题】难度 1.5/5,LCS 模板题
居家办公被催之后才明白的时间管理
深入理解 happens-before 原则
Basic usage and principle of fork/join framework
In depth analysis of error solutions and problems in dynamic loading of unity shadow and outline components
Precautions for use of IO interface interrupt of Jerry [chapter]
Prevent being rectified after 00? I. The company's recruitment requires that employees cannot sue the company
R language dplyr package arrange function sorts dataframe data, sorts dataframe data through multiple data columns, specifies the first field to be sorted in descending order, and does not specify the
C/s architecture
FileOutputStream
如何修改 node_modules 里的文件
AutoCAD - three pruning methods
Jianmu continuous integration platform v2.5.0 release
Heap heap sort TOPK
[tcapulusdb knowledge base] tcapulusdb doc acceptance - table creation approval introduction