当前位置:网站首页>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;
}
边栏推荐
- 程序员搞开源,读什么书最合适?
- Power Query数据格式的转换、拆分合并提取、删除重复项、删除错误、转置与反转、透视和逆透视
- Arduino hexapod robot
- Keepalive component cache does not take effect
- 【EI会议分享】2022年第三届智能制造与自动化前沿国际会议(CFIMA 2022)
- Cf:c. the third problem
- Gartner发布2022-2023年八大网络安全趋势预测,零信任是起点,法规覆盖更广
- Intensive learning weekly, issue 52: depth cuprl, distspectrl & double deep q-network
- Analysis of the combination of small program technology advantages and industrial Internet
- 95后CV工程师晒出工资单,狠补了这个,真香...
猜你喜欢
The population logic of the request to read product data on the sap Spartacus home page
KDD 2022 | 脑电AI助力癫痫疾病诊断
[EI conference sharing] the Third International Conference on intelligent manufacturing and automation frontier in 2022 (cfima 2022)
After Luke zettlemoyer, head of meta AI Seattle research | trillion parameters, will the large model continue to grow?
Set data real-time update during MDK debug
[groovy] XML serialization (use markupbuilder to generate XML data | create sub tags under tag closures | use markupbuilderhelper to add XML comments)
cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】
Cf:h. maximum and [bit operation practice + K operations + maximum and]
Exciting, 2022 open atom global open source summit registration is hot
The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
随机推荐
详细页返回列表保留原来滚动条所在位置
Getting started with devkit
cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】
Free chat robot API
anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
Recursive method converts ordered array into binary search tree
[Online gadgets] a collection of online gadgets that will be used in the development process
面试必刷算法TOP101之回溯篇 TOP34
Arduino hexapod robot
Logstash clear sincedb_ Path upload records and retransmit log data
China Taiwan strategy - Chapter 8: digital marketing assisted by China Taiwan
[EI conference sharing] the Third International Conference on intelligent manufacturing and automation frontier in 2022 (cfima 2022)
免费的聊天机器人API
Common API classes and exception systems
devkit入门
ADS-NPU芯片架构设计的五大挑战
The inconsistency between the versions of dynamic library and static library will lead to bugs
MIT doctoral thesis | robust and reliable intelligent system using neural symbol learning
logstash清除sincedb_path上传记录,重传日志数据
C language programming (Chapter 6 functions)