社区讨论
0pts 求调
P7547[BJWC2017] 太空飞船参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mkrodslo
- 此快照首次捕获于
- 2026/01/24 10:13 4 周前
- 此快照最后确认于
- 2026/01/24 17:52 4 周前
CPP
#include<bits/stdc++.h>
#define int long long
using namespace std;
bool ST;
inline int read(){
int x = 0, f = 1;
char ch = getchar();
while(!isdigit(ch)){
if(ch == '-') f = -1;
ch = getchar();
}
while(isdigit(ch)){
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
int n, k, a[300005], s[300005], dp[300005][25];
inline int f(int x){return x * x;}
bool ED;
signed main(){
n = read(), k = read();
for(int i = 1; i <= n; i++) s[i] = s[i - 1] + (a[i] = read());
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
for(int j = 1; j <= k; j++){
for(int i = 1; i <= n; i++){
for(int t = 0; t < i; t++){
dp[i][j] = min(dp[i][j], dp[t][j - 1] + f(s[i] - s[t]));
}
}
}
cout << f(k) * dp[n][k] - k * f(s[n]) << '\n';
cerr << 1.0 * abs(&ED - &ST) / 1024 / 1024 << " MB" << '\n';
return 0;
}
怎么看都不像会 WA 或 TLE 的()
回复
共 0 条回复,欢迎继续交流。
正在加载回复...