1 条题解
-
0赵青海 (huhe) LV 7 SU @ 2021-8-8 1:33:20
C++ :
#include<bits/stdc++.h> using namespace std; const int N = 105; int f[N][N], g[N][N], n; char c[N]; int main() { cin >> n; memset(f, -0x3f, sizeof(f)); memset(g, 0x3f, sizeof(g)); for (int i = 1; i <= n; i++) { cin >> c[i] >> f[i][i]; f[i + n][i + n] = g[i][i] = g[i + n][i + n] = f[i][i]; c[i + n] = c[i]; } for (int len = 2; len <= n; len++) for (int l = 1; l <= 2 * n - len + 1; l++) { int r = l + len - 1; for (int k = l; k <= r - 1; k++) { char op = c[k + 1]; int maxl = f[l][k], minl = g[l][k], maxr = f[k + 1][r], minr = g[k + 1][r]; if (op == 't') f[l][r] = max(f[l][r], maxl + maxr), g[l][r] = min(g[l][r], minl + minr); else { int x1 = maxl * maxr, x2 = maxl * minr, x3 = minl * maxr, x4 = minl * minr; f[l][r] = max(f[l][r], max(max(x1, x2), max(x3, x4))); g[l][r] = min(g[l][r], min(min(x2, x2), min(x3, x4))); } } } int res = -0x3f3f3f3f; for (int l = 1; l <= n + 1; l++) { int r = l + n - 1; if (f[l][r] > res)res = f[l][r]; } cout << res << endl; for (int l = 1; l <= n; l++) { int r = l + n - 1; if (f[l][r] == res) cout << l << ' '; } return 0; }
- 1
信息
- ID
- 194
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 8
- 标签
- 递交数
- 13
- 已通过
- 8
- 上传者