比赛 |
2024国庆练习3 |
评测结果 |
AAAAAAAAATTTTTTTTTTTTTTTT |
题目名称 |
划分 |
最终得分 |
36 |
用户昵称 |
flyfree |
运行时间 |
80.122 s |
代码语言 |
C++ |
内存使用 |
35.56 MiB |
提交时间 |
2024-10-06 17:47:37 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define ll __int128
#define MAXN 5010
#define N 1000000000000000
inline ll read(){
ll x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')f=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
inline void write(ll x){
if(x<0){
putchar('-');
x=x*(-1);
}
if(x>9)write(x/10);
putchar(x%10+'0');
}
ll n,type;
ll dp[MAXN][MAXN],a[MAXN],s[MAXN];
ll ans=N;
int main(){
freopen("2019partition.in","r",stdin);
freopen("2019partition.out","w",stdout);
n=read(),type=read();
for(int i=1;i<=n;i++){
a[i]=read();
s[i]=a[i]+s[i-1];
}
for(int i=1;i<=n;i++){
dp[i][0]=s[i]*s[i];
// write(dp[i][0]);
// cout<<" ";
for(int j=1;j<i;j++){
dp[i][j]=N;
for(int k=0;k<j;k++){
if(s[i]-s[j]>=s[j]-s[k])dp[i][j]=min(dp[i][j],(s[i]-s[j])*(s[i]-s[j])+dp[j][k]);
}
// write(dp[i][j]);
// cout<<" ";
}
// cout<<endl;
}
for(int i=0;i<n;i++)ans=min(ans,dp[n][i]);
write(ans);
return 0;
}