样例最大值过了,最小值没过
#include <bits/stdc++.h>
using namespace std;
int a[105], sa[105], dp1[105][105], dp2[105][105];
int main()
{
int n;
cin >> n;
memset(dp1, 127 / 2, sizeof(dp1));
for (int i = 1; i <= n; i++) cin >> a[i], sa[i] = sa[i - 1] + a[i], dp1[i][i] = 0;
for (int i = n - 1; i >= 1; i--)
{
for (int j = i + 1; j <= n; j++)
{
for (int k = i; k <= j - 1; k++)
{
dp1[i][j] = min(dp1[i][j], dp1[i][k] + dp1[k + 1][j] + sa[j] - sa[i - 1]);
dp2[i][j] = max(dp2[i][j], dp2[i][k] + dp2[k + 1][j] + sa[j] - sa[i - 1]);
}
}
}
cout << dp1[1][n] << endl << dp2[1][n] << endl;
return 0;
}