|
参加夏令营前写的代码,区间DP,把关键语句写错了。
- #include <iostream>
- #include <algorithm>
- #include <cstring>
- using namespace std;
- const int mm = 202;
- int d[mm], f[mm][mm], g[mm][mm], sum[mm];
- int n, i, j, k, maxn, minn, m;
- int main()
- {
- cin >> n;
- for (i = 1; i <= n; i++) cin >> d[i];
- for (i = 1; i <= n; i++) d[i + n] = d[i];
- m = n * 2;/*
- for (i = 1; i <= m; i++)
- for (j = 1; j <= m - i + 1; j++) g[j][i + j - 1] = 9999999;*/
- memset(g, 0x3f3f3f3f, sizeof(g));
- for (i = 1; i <= m; i++) f[i][i] = g[i][i] = 0;
- for (i = 1; i <= m; i++) sum[i] = sum[i - 1] + d[i];
- for (i = 2; i <= n; i++)
- for (j = 1; j <= m - i; j++)
- for (k = j; k <= i + j - 2; k++)
- {
- f[j][i + j - 1] = max(f[j][i + j - 1], f[j][k]+f[k + 1][i + j - 1] + sum[i + j - 1] - sum[j - 1]);
- g[j][i + j - 1] = min(g[j][i + j - 1], g[j][k]+g[k + 1][i + j - 1] + sum[i + j - 1] - sum[j - 1]);
- //if (i == n) cout << f[j][i + j - 1] << ' ' << g[j][i + j - 1] << endl;
- }
- maxn = 0;
- minn = 9999999;
- for (i = 1; i <= n; i++)
- {
- if (f[i][i + n - 1] > maxn) maxn = f[i][i + n - 1];
- if (g[i][i + n - 1] < minn) minn = g[i][i + n - 1];
- }
- cout << minn << endl
- << maxn;
- return 0;
- }
复制代码 |
|