Files
python/TangDou/AcWing/BeiBao/9_ErWei.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

28 lines
943 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n, m;
int f[N][N], v[N][N], w[N][N], s[N];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> s[i]; // 第i个分组中物品个数
for (int j = 1; j <= s[i]; j++)
cin >> v[i][j] >> w[i][j]; // 第i个分组中物品的体积和价值
}
for (int i = 1; i <= n; i++) // 每组
for (int j = 0; j <= m; j++) { // 每个合法体积
f[i][j] = f[i - 1][j]; // 如果一个都不要,那么这一组就相当于白费,给你机会也不中用,继承于i-1
for (int k = 1; k <= s[i]; k++) // 选择第k个
if (j >= v[i][k])
f[i][j] = max(f[i][j], f[i - 1][j - v[i][k]] + w[i][k]); // 枚举每一个PK一下大小
}
// 输出打表结果
printf("%d", f[n][m]);
return 0;
}