跳到正文

题解

题解:AT_abc390_e [ABC390E] Vitamin Balance

_Trangle_约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年1月26日
收录
2025年12月12日
更新
2026年11月19日
篇幅
约 2 分钟
获赞
1

版本

  1. v1当前

先将 33 种维生素分开处理。对于每种维生素,跑一遍背包,求 dpvdp_v 表示有 vv 点热量,最多能获得多少维生素。

最后再枚举三种维生素对应热量消耗,找出答案。

时间复杂度为 O(X(X+N))O(X(X+N))。

C++
#include <bits/stdc++.h>
#define range(i, b, e) for (auto i(b); i != (e); i++)
#define rep(i, b, e) for (auto i(b); i <= (e); i++)
#define req(i, b, e) for (auto i(b); i >= (e); i--)
using namespace std;
typedef long long LL;

const int N = 5e3, V = 5e3;
int n, v;
LL DP[3][V+5];
LL ans;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> n >> v;
	for (int i = 1, vit, typ, ka; i <= n; i++) {
		cin >> typ >> vit >> ka;
		typ--; //原编号为 1 2 3,变为 0 1 2。
		req(k, v, ka) DP[typ][k] = max(DP[typ][k], DP[typ][k-ka] + vit); //分开处理。
	}
	rep(i, 1, v) rep(j, 1, v-i) {
		int k = v-i-j; //确定了其中两个的热量,剩下的一个的热量也能确定。
		ans = max(ans, min({DP[0][i], DP[1][j], DP[2][k]}));
	}
	cout << ans;
	return 0;
}
原文