当前位置:网站首页>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
边栏推荐
- 正确遍历EntryList方法
- Leetcode - Sword finger offer 51 Reverse pairs in an array
- arcgis js 4. Add pictures to x map
- Redis transaction mechanism implementation process and principle, and use transaction mechanism to prevent inventory oversold
- 软件测试面试题-2022年大厂面试题合集
- 获取文件版权信息
- Some sudden program ideas (modular processing)
- 2.6 using recursion and stack - [tower of Hanoi problem]
- Docker compose configuration mysql, redis, mongodb
- 线性DP AcWing 898. 数字三角形
猜你喜欢
Counting class DP acwing 900 Integer partition
Simple understanding of ThreadLocal
堆 AcWing 838. 堆排序
Redis bloom filter
Does C language srand need to reseed? Should srand be placed in the loop? Pseudo random function Rand
计数类DP AcWing 900. 整数划分
模数转换器(ADC) ADE7913ARIZ 专为三相电能计量应用而设计
线性DP AcWing 899. 编辑距离
染色法判定二分图 AcWing 860. 染色法判定二分图
BOM DOM
随机推荐
LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
Linear DP acwing 896 Longest ascending subsequence II
Leetcode - Sword finger offer 59 - I, 59 - II
浏览器node事件循环
线性DP AcWing 899. 编辑距离
Drools executes the specified rule
Simple understanding of ThreadLocal
The coloring method determines the bipartite graph acwing 860 Chromatic judgement bipartite graph
Linear DP acwing 902 Shortest editing distance
Deep copy event bus
Input box assembly of the shutter package
Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)
Heap acwing 838 Heap sort
Drools executes string rules or executes a rule file
async/await 异步函数
深拷貝 事件總線
Leetcode - Sword finger offer 51 Reverse pairs in an array
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
China traffic sign detection data set