版本比较
AT_abc306_d 题解(格式修复版)
正文
增加 6 行删除 6 行
31 行未改动3233343536363738394015 行未改动56575859606061626364646566676828 行未改动97989910010110110210310410510610710710810911011110 行未改动12212312412512612612712812913012 行未改动31 行未改动
- 在这道菜上菜之前,高桥君感到舒适,而且他选择品尝这道菜。
- 在这道菜上菜之前,高桥君感到不适,而且他选择品尝这道菜。
综合上述 $3$ 种情况,可以得出状态转移方程:
$$dp_{i, 0} = \max\{dp_{i - 1, 0}, dp_{i - 1, 0} + Y_i, dp_{i - 1, 1} + Y_i \}15 行未改动
- 在这道菜上菜之前,高桥君感到舒适,而且他选择跳过这道菜。
故状态转移方程为:
$$dp_{i, 0} = dp_{i - 1, 0}$$
- 如果高桥君在对这道菜做出选择后感到不适,有以下 $2$ 种情况:
- 在这道菜上菜之前,高桥君感到不适,而且他选择跳过这道菜。
28 行未改动
- 当 $X_i = 0$ 时,
- $healthy = \max\{healthy, \max\{upset, healthy\} + Y_i\}$;
- $upset$ 无需更新。
- 当 $X_i = 1$ 时,
- $healthy$ 无需更新;
- $upset = \max\{upset, healthy + Y_i\}$。
时间复杂度仍为 $\mathcal{O}(N)$,但是空间复杂度已经被优化到了 $\mathcal{O}(1)$。
10 行未改动
int main() {
int n; scanf("%d", &n);
long long healthy = 0, upset = 0; for (int i = 0; i < n; ++i) { long long type, tastiness; scanf("%lld %lld", &type, &tastiness);12 行未改动