#include <iostream>
using namespace std;
const int N = 5e3 + 1;
int f[N][N], tot, n, a[N];
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i], tot += a[i];
for (int len = 2; len <= n; len += 2)
for (int l = 1, r = l + len - 1; r <= n; l++, r++)
f[l][r] = min(f[l + 1][r - 1] + max(a[l], a[r]), max(f[l + 2][r] + a[l], f[l][r - 2] + a[r]));
if (n & 1)
{
int res = max(tot - f[2][n], tot - f[1][n - 1]);
cout << res << endl;
}
else
cout << f[1][n] << endl;
}
这个代码除了第二个点MLE之外,第九个点偏大了一点,但是它的双倍经验USACO Traing3.3的一道题却能AC,所以是那道题的数据不够刁钻吗?这份代码哪里有问题呢?(第九个点n=800,所以不用考虑res计算正确与否)