当前位置:网站首页>区间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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- 测试左移和右移
- Initial JDBC programming
- Leetcode - Sword finger offer 51 Reverse pairs in an array
- Shutter encapsulated button
- Introduction to CPU instruction set
- [C language] convert decimal numbers to binary numbers
- High performance erasure code coding
- drools执行String规则或执行某个规则文件
- Deep Copy Event bus
- Mysql database foundation
猜你喜欢

drools中then部分的写法

高性能纠删码编码

What is the relationship between NFT and metauniverse? How to view the market? The future market trend of NFT

AAAI 2022 | Peking University & Ali Dharma Institute: pruning and compression of pre training language model based on comparative learning

BOM DOM

Map和Set

Map and set

(C language) 3 small Codes: 1+2+3+ · · +100=? And judge whether a year is a leap year or a normal year? And calculate the circumference and area of the circle?

CDA data analysis -- Introduction and use of aarrr growth model

From scratch, develop a web office suite (3): mouse events
随机推荐
字符串回文hash 模板题 O(1)判字符串是否回文
Interview with meituan, a 34 year old programmer, was rejected: only those under the age of 30 who work hard and earn little overtime
MySQL and PostgreSQL methods to grab slow SQL
Sub thread get request
Post request body content cannot be retrieved repeatedly
The programmer and the female nurse went on a blind date and spent 360. He packed leftovers and was stunned when he received wechat at night
Is the neural network (pinn) with embedded physical knowledge a pit?
Intel 内部指令 --- AVX和AVX2学习笔记
[old horse of industrial control] detailed explanation of Siemens PLC TCP protocol
How to write a pleasing English mathematical paper
There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes
Heap (priority queue)
Openssh remote enumeration username vulnerability (cve-2018-15473)
Intel internal instructions - AVX and avx2 learning notes
ThreadLocal的简单理解
Drools executes the specified rule
mysql数据库基础
Go学习笔记—基于Go的进程间通信
LeetCode—剑指 Offer 51. 数组中的逆序对
堆(优先级队列)