当前位置:网站首页>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 
边栏推荐
- Use sqoop to export ads layer data to MySQL
- JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)
- JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
- 2.6 using recursion and stack - [tower of Hanoi problem]
- Redis bloom filter
- Deep Copy Event bus
- spfa AcWing 852. spfa判断负环
- Enhance network security of kubernetes with cilium
- 线性DP AcWing 896. 最长上升子序列 II
- Docsify deploy IIS
猜你喜欢

Anti shake throttle

浏览器存储方案

Linear DP acwing 897 Longest common subsequence

Direct control PTZ PTZ PTZ PTZ camera debugging (c)

Redis bloom filter

Js10day (API phased completion, regular expression introduction, custom attributes, filtering sensitive word cases, registration module verification cases)

Use sqoop to export ads layer data to MySQL

堆 AcWing 839. 模拟堆

js1day(输入输出语法,数据类型,数据类型转换,var和let区别)

线性DP AcWing 899. 编辑距离
随机推荐
In development, why do you find someone who is paid more than you but doesn't write any code?
Dijkstra AcWing 850. Dijkstra finding the shortest circuit II
架构师必须了解的 5 种最佳软件架构模式
There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes
Interview questions for software testing - a collection of interview questions for large factories in 2022
2.7 binary tree, post order traversal - [FBI tree]
Floyd AcWing 854. Floyd求最短路
Typora+docsify quick start
Use MySQL events to regularly perform post seven world line tasks
JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)
模块化 CommonJS ES Module
Heap acwing 838 Heap sort
浏览器存储方案
Introduction to CPU instruction set
深拷贝 事件总线
Deep copy event bus
Why do programmers have the idea that code can run without moving? Is it poisonous? Or what?
Adding database driver to sqoop of cdh6
[FFH] little bear driver calling process (take calling LED light driver as an example)
Interview with meituan, a 34 year old programmer, was rejected: only those under the age of 30 who work hard and earn little overtime