You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
/**
6.
1
nv
ic[i]w[i]
使
2
g(0 ~ g-1)
ici wi gi()
*/
using namespace std;
#define maxV 1000
#define maxG 100
#define maxN 100
int main(void) {
int cases, n, v, g, gi;
int f[maxV];
int ci[maxN], wi[maxN];
freopen("../6.txt", "r", stdin);
cin >> cases;
while (cases--) {
memset(f, 0, sizeof(f));
cin >> n >> v >> g;
vector<vector<int> > gMap(g);
for (int i = 0; i < n; i++) {
cin >> ci[i] >> wi[i] >> gi;
gMap[gi].push_back(i);
}
for (int i = 0; i < g; i++) {
for (int j = v; j >= 0; j--) {
for (int k = 0; k < gMap[i].size(); k++) {
if (j >= ci[gMap[i][k]])
f[j] = max(f[j], f[j - ci[gMap[i][k]]] + wi[gMap[i][k]]);
}
}
}
cout << f[v] << endl;
}
}