当前位置:网站首页>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;
}边栏推荐
- [Online gadgets] a collection of online gadgets that will be used in the development process
- XML Configuration File
- 数据分析思维分析方法和业务知识——分析方法(三)
- Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?
- The growth path of test / development programmers, the problem of thinking about the overall situation
- synchronized 和 ReentrantLock
- Analysis of the combination of small program technology advantages and industrial Internet
- 95后CV工程师晒出工资单,狠补了这个,真香...
- Folding and sinking sand -- weekly record of ETF
- [simple implementation of file IO]
猜你喜欢

Keepalive component cache does not take effect

Free chat robot API

MIT doctoral thesis | robust and reliable intelligent system using neural symbol learning

After 95, the CV engineer posted the payroll and made up this. It's really fragrant

anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败

Exciting, 2022 open atom global open source summit registration is hot

Common API classes and exception systems

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

MIT博士论文 | 使用神经符号学习的鲁棒可靠智能系统
![[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)
随机推荐
[groovy] compile time meta programming (compile time method interception | method interception in myasttransformation visit method)
Novice entry depth learning | 3-6: optimizer optimizers
MYSQL GROUP_ The concat function realizes the content merging of the same ID
Zhuhai laboratory ventilation system construction and installation instructions
Opencv classic 100 questions
Intensive learning weekly, issue 52: depth cuprl, distspectrl & double deep q-network
Power query data format conversion, Split Merge extraction, delete duplicates, delete errors, transpose and reverse, perspective and reverse perspective
如何制作自己的機器人
View class diagram in idea
Ubantu check cudnn and CUDA versions
Differences between standard library functions and operators
【文件IO的简单实现】
Finding the nearest common ancestor of binary tree by recursion
[groovy] JSON serialization (jsonbuilder builder | generates JSON string with root node name | generates JSON string without root node name)
Spark DF adds a column
MIT doctoral thesis | robust and reliable intelligent system using neural symbol learning
Spark-SQL UDF函数
RAID disk redundancy queue
面试必刷算法TOP101之回溯篇 TOP34
uniapp开发,打包成H5部署到服务器