1 条题解
-
0
C++ :
#include <cstdio> #include <cstring> #include <algorithm> #define ll long long using namespace std; ll n, a[3010], s[3010], d; ll g[3010][3010], f[3010]; inline int read() { int x = 0; char c = getchar(); while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return x; } int main() { n = read(); for (int i = 1; i <= n; i++) a[i] = read(), s[i] = s[i - 1] + a[i]; for (int j = 1; j < n; j++) for (int i = 1; i <= n - j; i++) g[i][i + j] = g[i + 1][i + j] + min((s[i + j] - s[i]) * 2, 3 * j * a[i] + s[i + j] - s[i]); memset(f, 5, sizeof(f)); f[0] = 0; for (int i = 1; i <= n; i++) for (int j = 0; j < i; j++) f[i] = min(f[i], f[j] + g[j + 1][i] + (3 * (i - j - 1) + i - j + 1) * (s[n] - s[i])); printf("%lld\n", f[n]); return 0; }
- 1
信息
- ID
- 983
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者