0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-09 01:58:48 +00:00
OI-codes/AcWing/9/9.cpp

40 lines
765 B
C++
Raw Normal View History

#include <iostream>
2022-06-01 01:45:41 +00:00
#include <cstring>
#include <limits>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 105;
int n, m, s[N], v[N][N], w[N][N], f[N];
int main() {
std::ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> s[i];
for (int j = 1; j <= s[i]; j++) {
cin >> v[i][j] >> w[i][j];
}
}
memset(f, 0xcf, sizeof(f));
f[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = m; j >= 0; j--) {
for (int k = 1; k <= s[i]; k++) {
if (j >= v[i][k]) {
f[j] = std::max(f[j], f[j - v[i][k]] + w[i][k]);
}
}
}
}
cout << f[m] << endl;
return 0;
}