mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 16:38:47 +00:00
9. 分组背包问题
https://www.acwing.com/problem/content/submission/code_detail/13070405/
This commit is contained in:
parent
5d654e6b47
commit
dd0c2a1704
39
AcWing/9/9.cpp
Normal file
39
AcWing/9/9.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#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;
|
||||
}
|
BIN
AcWing/9/data/2.ans
(Stored with Git LFS)
Normal file
BIN
AcWing/9/data/2.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AcWing/9/data/2.in
(Stored with Git LFS)
Normal file
BIN
AcWing/9/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user