当前位置:网站首页>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;
}
边栏推荐
- MCU realizes OTA online upgrade process through UART
- 面试必刷算法TOP101之回溯篇 TOP34
- MYSQL GROUP_ The concat function realizes the content merging of the same ID
- esxi的安装和使用
- Finding the nearest common ancestor of binary tree by recursion
- Fibonacci number
- 数据分析思维分析方法和业务知识——分析方法(三)
- 2022-02-13 work record -- PHP parsing rich text
- 云导DNS和知识科普以及课堂笔记
- Introduction of motor
猜你喜欢
Common API classes and exception systems
I'm interested in watching Tiktok live beyond concert
Cf:h. maximum and [bit operation practice + K operations + maximum and]
Anconda download + add Tsinghua +tensorflow installation +no module named 'tensorflow' +kernelrestart: restart failed, kernel restart failed
ubantu 查看cudnn和cuda的版本
【EI会议分享】2022年第三届智能制造与自动化前沿国际会议(CFIMA 2022)
程序员搞开源,读什么书最合适?
Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?
MCU通过UART实现OTA在线升级流程
How to use the flutter framework to develop and run small programs
随机推荐
Promise
Zhuhai's waste gas treatment scheme was exposed
curlpost-php
RAID disk redundancy queue
Comment faire votre propre robot
The relationship between FPGA internal hardware structure and code
Logstash clear sincedb_ Path upload records and retransmit log data
Recursive method to realize the insertion operation in binary search tree
Programmer growth Chapter 9: precautions in real projects
Four commonly used techniques for anti aliasing
ADS-NPU芯片架构设计的五大挑战
logstash清除sincedb_path上传记录,重传日志数据
Arduino hexapod robot
Convert binary search tree into cumulative tree (reverse middle order traversal)
ubantu 查看cudnn和cuda的版本
Four dimensional matrix, flip (including mirror image), rotation, world coordinates and local coordinates
关于#数据库#的问题:(5)查询库存表中每本书的条码、位置和借阅的读者编号
Finding the nearest common ancestor of binary search tree by recursion
After 95, the CV engineer posted the payroll and made up this. It's really fragrant
Power query data format conversion, Split Merge extraction, delete duplicates, delete errors, transpose and reverse, perspective and reverse perspective