当前位置:网站首页>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;
}
边栏推荐
- Basic introduction and source code analysis of webrtc threads
- The detailed page returns to the list and retains the original position of the scroll bar
- Keepalive component cache does not take effect
- 【文件IO的简单实现】
- Four dimensional matrix, flip (including mirror image), rotation, world coordinates and local coordinates
- esxi的安装和使用
- [simple implementation of file IO]
- BiShe - College Student Association Management System Based on SSM
- Why can't mathematics give machine consciousness
- MYSQL GROUP_ The concat function realizes the content merging of the same ID
猜你喜欢
MYSQL GROUP_ The concat function realizes the content merging of the same ID
Study diary: February 13, 2022
MySQL storage engine
The population logic of the request to read product data on the sap Spartacus home page
Analysis of the combination of small program technology advantages and industrial Internet
How to use the flutter framework to develop and run small programs
Ffmpeg captures RTSP images for image analysis
关于#数据库#的问题:(5)查询库存表中每本书的条码、位置和借阅的读者编号
数据分析思维分析方法和业务知识——分析方法(二)
[groovy] compile time meta programming (AST syntax tree conversion with annotations | define annotations and use groovyasttransformationclass to indicate ast conversion interface | ast conversion inte
随机推荐
Spark AQE
cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】
MYSQL GROUP_ The concat function realizes the content merging of the same ID
Idea remotely submits spark tasks to the yarn cluster
Data analysis thinking analysis methods and business knowledge - analysis methods (III)
Recursive method to realize the insertion operation in binary search tree
Cf:c. the third problem
Building core knowledge points
[groovy] compile time metaprogramming (compile time method injection | method injection using buildfromspec, buildfromstring, buildfromcode)
The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
Spark SQL null value, Nan judgment and processing
Opencv classic 100 questions
图解网络:TCP三次握手背后的原理,为啥两次握手不可以?
[groovy] JSON serialization (convert class objects to JSON strings | convert using jsonbuilder | convert using jsonoutput | format JSON strings for output)
Novice entry depth learning | 3-6: optimizer optimizers
Kotlin core programming - algebraic data types and pattern matching (3)
Questions about database: (5) query the barcode, location and reader number of each book in the inventory table
程序员成长第九篇:真实项目中的注意事项
MobileNet系列(5):使用pytorch搭建MobileNetV3并基于迁移学习训练
如何制作自己的机器人