当前位置:网站首页>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;
}边栏推荐
- Idea remotely submits spark tasks to the yarn cluster
- 视频直播源码,实现本地存储搜索历史记录
- Anconda download + add Tsinghua +tensorflow installation +no module named 'tensorflow' +kernelrestart: restart failed, kernel restart failed
- cf:D. Insert a Progression【关于数组中的插入 + 绝对值的性质 + 贪心一头一尾最值】
- logstash清除sincedb_path上传记录,重传日志数据
- MIT doctoral thesis | robust and reliable intelligent system using neural symbol learning
- Spark SQL空值Null,NaN判断和处理
- Hundreds of lines of code to implement a JSON parser
- Power Query数据格式的转换、拆分合并提取、删除重复项、删除错误、转置与反转、透视和逆透视
- Yolov5, pychar, Anaconda environment installation
猜你喜欢
![[groovy] JSON serialization (jsonbuilder builder | generates JSON string with root node name | generates JSON string without root node name)](/img/dd/bffe27b04d830d70f30df95a82b3d2.jpg)
[groovy] JSON serialization (jsonbuilder builder | generates JSON string with root node name | generates JSON string without root node name)

Common API classes and exception systems

Introduction of motor

BiShe - College Student Association Management System Based on SSM

cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】
![[groovy] compile time metaprogramming (compile time method injection | method injection using buildfromspec, buildfromstring, buildfromcode)](/img/e4/a41fe26efe389351780b322917d721.jpg)
[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

Fibonacci number
![[groovy] JSON serialization (convert class objects to JSON strings | convert using jsonbuilder | convert using jsonoutput | format JSON strings for output)](/img/52/021931181ad3f4bef271b4e98105c2.jpg)
[groovy] JSON serialization (convert class objects to JSON strings | convert using jsonbuilder | convert using jsonoutput | format JSON strings for output)

How to use the flutter framework to develop and run small programs
随机推荐
[groovy] JSON serialization (jsonbuilder builder | generates JSON string with root node name | generates JSON string without root node name)
cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】
logstash清除sincedb_path上传记录,重传日志数据
Synchronized and reentrantlock
RAID disk redundancy queue
Power Query数据格式的转换、拆分合并提取、删除重复项、删除错误、转置与反转、透视和逆透视
[groovy] compile time meta programming (compile time method interception | method interception in myasttransformation visit method)
Lone brave man
uniapp开发,打包成H5部署到服务器
STM32 key chattering elimination - entry state machine thinking
cf:D. Insert a Progression【关于数组中的插入 + 绝对值的性质 + 贪心一头一尾最值】
Common API classes and exception systems
Leetcode 44 Wildcard matching (2022.02.13)
BiShe - College Student Association Management System Based on SSM
How spark gets columns in dataframe --column, $, column, apply
[groovy] compile time metaprogramming (compile time method injection | method injection using buildfromspec, buildfromstring, buildfromcode)
Four commonly used techniques for anti aliasing
XML Configuration File
Recoverable fuse characteristic test
curlpost-php