当前位置:网站首页>[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;
}边栏推荐
- Failed to start component [StandardEngine[Catalina]. StandardHost[localhost]]
- Unity packaging webgl uses IIS to solve the error
- High quality domestic stereo codec cjc8988, pin to pin replaces wm8988
- CAD secondary development +nettopologysuite+pgis reference multi version DLL
- idea创建类时自动添加注释
- Difficulty calculation of Ethereum classic
- Install and manage multiple versions of PHP under mac
- 整型提升和大小端字节序
- easyui下拉框选中触发事件
- 手把手教你用Ucos
猜你喜欢

AutoCAD C# 多段线小锐角检测

Sharing tips for efficient scripting

Linux Mysql 实现root用户不用密码登录

Freeswitch使用originate转dialplan

CAD secondary development +nettopologysuite+pgis reference multi version DLL

Working principle of es9023 audio decoding chip

Triode driven brushless motor

socke. IO long connection enables push, version control, and real-time active user statistics

Socket. Io long Connection Push, version Control, Real - Time Active user volume Statistics

搭建你jmeter+jenkins+ant
随机推荐
【Paper Reading-3D Detection】Fully Convolutional One-Stage 3D Object Detection on LiDAR Range Images
FPGA - 7 Series FPGA selectio -07- iserdese2 of advanced logic resources
freeswitch设置最大呼叫时长
Linked list (III) - reverse linked list
Note that JPA uses a custom VO to receive jpql query results
异常处理(一)——空指针和数组索引越界
阿里云短信服务(完整指南),短信发送功能实现。
Students who do not understand the code can also send their own token. The current universal dividend model can be divided into BSC and any generation B
链表(一)——移除链表元素
Introduction to openscap
@RequestParam
AutoCAD C# 多段線小銳角檢測
How to open UMD, KMD log and dump diagrams in CAMX architecture
ImportError: cannot import name 'ensure_ dir_ Possible solutions for exists'
YYGH-BUG-03
整型提昇和大小端字節序
Eyebeam advanced settings
ThreadLocal
Drop down list processing in Web Automation
AttributeError: 'callable_ iterator' object has no attribute 'next'