背包问题变形 | #小红升装备#
小红升装备
https://www.nowcoder.com/practice/4a6870e22843440ea6bccbf525ece039
背包问题变形
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
const int N = 1e5 + 10, MOD = 998244353;
const LL INF = 1e18;
struct F {
int a, b, c, d, e;
};
void solve() {
int n, m;
cin >> n >> m;
vector<F> a(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> a[i].a >> a[i].b >> a[i].c >> a[i].d >> a[i].e;
}
vector<vector<LL>> f(n + 1, vector<LL>(m + 1));
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= m; ++j) {
f[i][j] = f[i - 1][j];
if (j >= a[i].b) {
f[i][j] = max(f[i][j], f[i - 1][j - a[i].b] + a[i].a);
int cnt = a[i].e;
int cost = a[i].b;
LL v = a[i].a;
for (int k = 1; k <= cnt; ++k) {
cost += a[i].c;
v += a[i].d;
if (cost > j) break;
f[i][j] = max(f[i][j], f[i - 1][j - cost] + v);
}
}
}
}
LL ans = f[n][m];
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
while (T--) solve();
return 0;
}
深信服公司福利 906人发布