虚空终端 • 2年前
using namespace std; int q[5005]; int p[5005]; int dp[5005][105]; int a;
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> q[i];
p[1] = q[1];
for (int i = 2; i <= n; i++)
p[i] = p[i - 1] + q[i];
for (int i = 1; i <= n; i++)
dp[i][1] = p[i];
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
if (i - 1 == j) {
dp[i][j + 1] = q[i];
for (int x = 1; x <= i; x++)
dp[i][j + 1] = max(q[x], dp[i][j + 1]);
} else {
dp[i][j + 1] = max(dp[i - 1][j], p[n] - p[i - 1]);
for (int x = 1; i - x >= j + 1; x++)
dp[i][j + 1] = min(max(dp[i - x][j], p[n] - p[i - x]), dp[i][j + 1]);
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
cout << dp[i][j] << ' ';
cout << endl;
}
for (int i = 1; i <= n; i++)
cout << p[i] << ' ';
return 0;
}
评论:
请先登录,才能进行评论