当前位置:网站首页>Interval DP acwing 282 Stone merging
Interval DP acwing 282 Stone merging
2022-07-02 12:43:00 【T_ Y_ F666】
Section DP AcWing 282. Stone merging
Original link
Algorithm tags
Dynamic programming Section DP
Ideas

Code
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>b;--i)
using namespace std;
const int N = 505;
int a[N], s[N], f[N][N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n=read();
rep(i, 1, n+1){
a[i]=read();
}
rep(i, 1, n+1){
a[i]+=a[i-1];
}
// Length of gravel pile If the length of the stone pile is 1 f[1][1] Initial value 0, In line with the question
rep(len, 2, n+1){
// The starting point of the stone pile
for(int i=1; i+len-1<=n; ++i){
// The left and right ends of the gravel pile
int l=i, r=i+len-1;
f[l][r]=1e8;
// Stone dividing point
rep(k, l, r){
f[l][r]=min(f[l][r], f[l][k]+f[k][r]+s[r]-s[l-1]);
}
}
}
printf("%lld", f[1][n]);
return 0;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)
- Leetcode - Sword finger offer 37, 38
- 绕过ObRegisterCallbacks需要驱动签名方法
- Leetcode - Sword finger offer 59 - I, 59 - II
- Drools executes the specified rule
- 线性DP AcWing 898. 数字三角形
- Counting class DP acwing 900 Integer partition
- 1380. Lucky numbers in the matrix [two-dimensional array, matrix]
- C#运算符
- Interview with meituan, a 34 year old programmer, was rejected: only those under the age of 30 who work hard and earn little overtime
猜你喜欢

Programmers can't find jobs after the age of 35? After reading this article, you may be able to find the answer

包管理工具

应用LNK306GN-TL 转换器、非隔离电源

Floyd AcWing 854. Floyd求最短路

线性DP AcWing 902. 最短编辑距离

趣味 面试题

线性DP AcWing 899. 编辑距离

Win10 system OmniPeek wireless packet capturing network card driver failed to install due to digital signature problem solution

线性DP AcWing 897. 最长公共子序列

Counting class DP acwing 900 Integer partition
随机推荐
Async/await asynchronous function
Does C language srand need to reseed? Should srand be placed in the loop? Pseudo random function Rand
Linear DP acwing 895 Longest ascending subsequence
There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes
Rust search server, rust quick service finding tutorial
OpenCV中cv2.VideoWriter_fourcc()函数和cv2.VideoWriter()函数的结合使用
移动式布局(流式布局)
C#修饰符
Shutter encapsulated button
Heap acwing 838 Heap sort
JSON序列化 与 解析
JDBC prevent SQL injection problems and solutions [preparedstatement]
3 A VTT端接 稳压器 NCP51200MNTXG资料
About wechat enterprise payment to change x509certificate2 read certificate information, publish to the server can not access the solution
Heap acwing 839 Simulated reactor
spfa AcWing 851. spfa求最短路
. Net wechat message template push
Linear DP acwing 896 Longest ascending subsequence II
Dijkstra AcWing 850. Dijkstra finding the shortest circuit II
Deep Copy Event bus