当前位置:网站首页>282. Stone consolidation (interval DP)
282. Stone consolidation (interval DP)
2022-07-06 00:53:00 【seez】

Application interval dp To think

State means : All merged i Pile up to the third j A collection of fruits
attribute :min
State calculation / subset division : Which two piles of fruits were merged last time , That is, where was the last breakpoint
- The break point is i+1 Merge [i] and [i+1,j] dp[i][j]=dp[i][i]+dp[i+1][j]+sum[i,j]
- The break point is i+2 Merge [i,i+1] and [i+2,j] dp[i][j]=dp[i][i+1]+dp[i+2][j]+sum[i,j]
- ...
- The break point is j-1 Merge in [i,j-1] and [j] dp[i][j]=dp[i][j-1]+dp[j][j]+sum[i,j]
initialization : All are infinite
The border :dp[i][i]=0
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=305;
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],s[i]=s[i-1]+a[i];
memset(dp,0x3f,sizeof dp);
for(int i=1;i<=n;i++)
dp[i][i]=0;
for(int len=2;len<=n;len++)
for(int i=1;i+len-1<=n;i++)
{
int j=i+len-1;
for(int k=i;k<j;k++)
dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+s[j]-s[i-1]);
}
cout<<dp[1][n];
return 0;
}边栏推荐
- The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
- A preliminary study of geojson
- Leetcode 44 Wildcard matching (2022.02.13)
- 程序员搞开源,读什么书最合适?
- MobileNet系列(5):使用pytorch搭建MobileNetV3并基于迁移学习训练
- Folding and sinking sand -- weekly record of ETF
- CTF daily question day44 rot
- Synchronized and reentrantlock
- 测试/开发程序员的成长路线,全局思考问题的问题......
- SAP Spartacus home 页面读取 product 数据的请求的 population 逻辑
猜你喜欢

How to make your own robot

View class diagram in idea

Data analysis thinking analysis methods and business knowledge - analysis methods (III)

程序员搞开源,读什么书最合适?

Cve-2017-11882 reappearance

Anconda download + add Tsinghua +tensorflow installation +no module named 'tensorflow' +kernelrestart: restart failed, kernel restart failed

VSphere implements virtual machine migration

What is the most suitable book for programmers to engage in open source?

Extension and application of timestamp
![[groovy] XML serialization (use markupbuilder to generate XML data | create sub tags under tag closures | use markupbuilderhelper to add XML comments)](/img/d4/4a33e7f077db4d135c8f38d4af57fa.jpg)
[groovy] XML serialization (use markupbuilder to generate XML data | create sub tags under tag closures | use markupbuilderhelper to add XML comments)
随机推荐
如何制作自己的機器人
A preliminary study of geojson
Ffmpeg captures RTSP images for image analysis
Spark AQE
The relationship between FPGA internal hardware structure and code
SAP Spartacus home 页面读取 product 数据的请求的 population 逻辑
Curlpost PHP
【文件IO的简单实现】
The inconsistency between the versions of dynamic library and static library will lead to bugs
vSphere实现虚拟机迁移
Cannot resolve symbol error
cf:D. Insert a Progression【关于数组中的插入 + 绝对值的性质 + 贪心一头一尾最值】
Spark SQL空值Null,NaN判断和处理
[groovy] compile time meta programming (compile time method interception | method interception in myasttransformation visit method)
Free chat robot API
几百行代码实现一个 JSON 解析器
KDD 2022 | 脑电AI助力癫痫疾病诊断
【EI会议分享】2022年第三届智能制造与自动化前沿国际会议(CFIMA 2022)
95后CV工程师晒出工资单,狠补了这个,真香...
How spark gets columns in dataframe --column, $, column, apply