当前位置:网站首页>[interval DP] stone consolidation
[interval DP] stone consolidation
2022-06-28 06:26:00 【Nathan Qian】
subject
282. Stone merging - AcWing Question bank
AcWing 282. Stone merging ( Section DP Detailed analysis of template questions ) - AcWing
explain
- State means :f(i,j) It means that you will i To j A collection of schemes combined into a pile , The attribute is min
- State calculation :i<j when ,f(i,j)=min(f(i,k)+f(k+1,j)+s[j]-s[i-1] i=j when ,f(i,i)=0
- The first layer of the loop is the enumeration interval length , The second dimension is fixed i The location of , Ensure that each state is calculated to
- The final answer is (1~n) Total interval of , namely f(1,n)
Code segment
Section DP Templates
for (int i = 1; i <= n; i++) {
dp[i][i] = Initial value
}
for (int len = 2; len <= n; len++) // Interval length
for (int i = 1; i + len - 1 <= n; i++) { // Enumeration starting point
int j = i + len - 1; // Interval end point
for (int k = i; k < j; k++) { // Enumerate split points , Construct the state transition equation
dp[i][j] = max(dp[i][j], dp[i][k] + dp[k + 1][j] + w[i][j]);
}
}
#include<iostream>
using namespace std;
const int N=310;
int a[N],s[N],f[N][N],n;
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
s[i]=a[i]+s[i-1];
}
for(int i=1;i<=n;i++)
f[i][i]=0;
for(int len=2;len<=n;len++)
for(int i=1;i+len-1<=n;i++)
{
int j=i+len-1;
f[i][j]=1e9;
for(int k=i;k<j;k++)
{
f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]+s[j]-s[i-1]);
}
}
cout<<f[1][n]<<endl;
}边栏推荐
- @The reason why the Autowired annotation is empty
- YYGH-BUG-02
- FPGA - 7 Series FPGA selectio -09- io of advanced logic resources_ FIFO
- Yygh-6-wechat login
- RN7302三相电量检测(基于STM32单片机)
- Lombok @equalsandhashcode annotation how to make objects The equals () method compares only some attributes
- YYGH-BUG-03
- AttributeError: 'callable_iterator' object has no attribute 'next'
- easyui 重置多条件查询
- Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance
猜你喜欢

AutoCAD C# 多段线自相交检测

fpm工具安装

Linked list (I) - remove linked list elements

Rn7302 three-phase electric quantity detection (based on STM32 single chip microcomputer)

YOLOv5增加小目标检测层

搭建你jmeter+jenkins+ant

Camx架构开UMD、KMD log以及dump图的方式

Freeswitch uses origin to dialplan

MySQL (I) - Installation

Drop down list processing in Web Automation
随机推荐
Openharmony gnawing paper growth plan -- json-rpc
链表(一)——移除链表元素
Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
Install redis on windows and permanently change the password, and integrate redis with the SSM framework
手把手教你用Ucos
freeswitch使用mod_shout模块播放mp3
【Paper Reading-3D Detection】Fully Convolutional One-Stage 3D Object Detection on LiDAR Range Images
FPM tool installation
Floating and positioning
Sharing tips for efficient scripting
Yygh-6-wechat login
创建格式化时间,格式化时区的gson对象。json解析时间格式化 ZonedDateTime
移动广告发展动向:撬动存量,精细营销
Triode driven brushless motor
Unity packaging webgl uses IIS to solve the error
High quality domestic stereo codec cjc8988, pin to pin replaces wm8988
SQL and list de duplication
阿里云短信服务(完整指南),短信发送功能实现。
socke.io长连接实现推送、版本控制、实时活跃用户量统计
Paper recommendation: efficientnetv2 - get smaller models and faster training speed through NAS, scaling and fused mbconv