当前位置:网站首页>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 
边栏推荐
- 深拷貝 事件總線
- C#运算符
- AI mid stage technology research
- 堆 AcWing 838. 堆排序
- ASP. Net MVC default configuration, if any, jumps to the corresponding program in the specified area
- China traffic sign detection data set
- Less than three months after the programmer was hired, the boss wanted to launch the app within one month. If he was dissatisfied, he was dismissed immediately
- 正确遍历EntryList方法
- Docsify deploy IIS
- CV2 in OpenCV VideoWriter_ Fourcc() function and cv2 Combined use of videowriter() function
猜你喜欢

AI mid stage technology research

防抖 节流

深拷贝 事件总线

High performance erasure code coding

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

Distributed machine learning framework and high-dimensional real-time recommendation system

架构师必须了解的 5 种最佳软件架构模式

spfa AcWing 852. SPFA judgement negative ring

BOM DOM

bellman-ford AcWing 853. Shortest path with side limit
随机推荐
Leetcode - < dynamic planning special> Jianzhi offer 19, 49, 60
Fluent fluent library encapsulation
Find the common ancestor of any two numbers in a binary tree
This "little routine" is set on the dough cake of instant noodles. No wonder programmers are always hungry
基于STM32的OLED 屏幕驱动
架构师必须了解的 5 种最佳软件架构模式
深拷贝 事件总线
深拷貝 事件總線
Drools dynamically add, modify, and delete rules
H5 to app
Less than three months after the programmer was hired, the boss wanted to launch the app within one month. If he was dissatisfied, he was dismissed immediately
Bom Dom
Docsify deploy IIS
Writing method of then part in drools
绕过ObRegisterCallbacks需要驱动签名方法
[ybtoj advanced training guidance] judgment overflow [error]
Dijkstra AcWing 850. Dijkstra finding the shortest circuit II
Rust search server, rust quick service finding tutorial
About the loading of layer web spring layer components, the position of the layer is centered
Use sqoop to export ads layer data to MySQL