当前位置:网站首页>区间DP AcWing 282. 石子合并
区间DP AcWing 282. 石子合并
2022-07-02 09:43:00 【T_Y_F666】
区间DP AcWing 282. 石子合并
原题链接
算法标签
动态规划 区间DP
思路

代码
#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];
}
// 石子堆长度 若石子堆长度为1 f[1][1]初始值0,符合题意
rep(len, 2, n+1){
// 石子堆起点
for(int i=1; i+len-1<=n; ++i){
// 石子堆左右端点
int l=i, r=i+len-1;
f[l][r]=1e8;
// 石子分割点
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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- lombok常用注解
- Sparkcontext: error initializing sparkcontext solution
- Leetcode14 longest public prefix
- The differences and relationships among port, targetport, nodeport and containerport in kubenetes
- Take you ten days to easily finish the finale of go micro services (distributed transactions)
- [C language] convert decimal numbers to binary numbers
- When uploading a file, the server reports an error: iofileuploadexception: processing of multipart / form data request failed There is no space on the device
- [FFH] little bear driver calling process (take calling LED light driver as an example)
- Addition, deletion, modification and query of MySQL table (Advanced)
- Drools terminates the execution of other rules after executing one rule
猜你喜欢

测试左移和右移
![[ybtoj advanced training guidance] cross the river [BFS]](/img/4e/83f14452ea6410768cdd01e725af2e.jpg)
[ybtoj advanced training guidance] cross the river [BFS]

Performance tuning project case

AI mid stage technology research

Docker compose configuration mysql, redis, mongodb

Sweetheart leader: Wang Xinling

There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes

Simple use of drools decision table

二分刷题记录(洛谷题单)区间的甄别

(C language) input a line of characters and count the number of English letters, spaces, numbers and other characters.
随机推荐
Why do programmers have the idea that code can run without moving? Is it poisonous? Or what?
[FFH] little bear driver calling process (take calling LED light driver as an example)
Find the common ancestor of any two numbers in a binary tree
堆(優先級隊列)
Sse/avx instruction set and API of SIMD
post请求体内容无法重复获取
OpenCV中cv2.VideoWriter_fourcc()函数和cv2.VideoWriter()函数的结合使用
CDA数据分析——AARRR增长模型的介绍、使用
深拷貝 事件總線
Record the range of data that MySQL update will lock
Drools terminates the execution of other rules after executing one rule
2.7 binary tree, post order traversal - [FBI tree]
BOM DOM
arcgis js 4. Add pictures to x map
SparkContext: Error initializing SparkContext解决方法
Shutter encapsulated button
怎样写一篇赏心悦目的英文数学论文
Input a three digit number and output its single digit, ten digit and hundred digit.
Is the neural network (pinn) with embedded physical knowledge a pit?
子线程获取Request