constint N = 55; constint inf = 0x3f3f3f3f; int dp1[110][110], dp2[55][510], dp3[510][5]; int n, m, t, p; string s; map<string, int> id; structnode { int x, y; }; vector<node> v[N];
voidsolve(){ cin >> n; for (int i = 1; i <= n; ++i) { cin >> s; id[s] = i; } cin >> m; for (int i = 1; i <= m; ++i) { int xx, yy; cin >> s >> xx >> yy; v[id[s]].push_back((node){xx, yy}); } cin >> t >> p; memset(dp1, 0x3f, sizeof(dp1)); memset(dp2, 0, sizeof(dp2)); memset(dp3, -0x3f, sizeof(dp3)); for (int i = 1; i <= n; ++i) { dp1[i][0] = 0; int len = v[i].size(); for (int j = 0; j < len; ++j) { for (int k = 109; k >= v[i][j].x; --k) { dp1[i][k] = min(dp1[i][k], dp1[i][k-v[i][j].x] + v[i][j].y); } } for (int k = 109; k >= 100; --k) { dp1[i][k] = min(dp1[i][k+1], dp1[i][k]); } for (int k = 1 ; k <= 100; ++k) { if (dp1[i][k] > 500) continue; dp2[i][dp1[i][k]] = max(dp2[i][dp1[i][k]], k); } } dp3[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = t; j >= 1; --j) { for (int k = p; k >= 1; --k) dp3[j][k] = dp3[j][k-1]; dp3[j][0] = -inf; for (int k = 0; k <= p; ++k) { int up = min(dp1[i][100], j); for (int l = 1; l <= up; ++l) { if (dp2[i][l] >= 60) dp3[j][k] = max(dp3[j][k], dp3[j - l][k] + dp2[i][l]); elseif (k > 0) dp3[j][k] = max(dp3[j][k], dp3[j-l][k-1] + dp2[i][l]); } } } dp3[0][0] = -inf; } int ans = -1; for (int i = 1; i <= t; ++i) { for (int j = 0; j <= p; ++j) { ans = max(dp3[i][j], ans); } } cout << ans << endl; id.clear(); for (int i = 1; i <= n; ++i) v[i].clear(); }
intmain(){ ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int T; cin >> T; while (T--) { solve(); } return0; }
int n, m, t, p; structnode { int x, y; }; vector<node> v[55]; map<string, int> id; int f[55][510]; // 第i门科目,前j天能获得的最大分数 int dp[55][510][5]; // 前i门科目,前j天,挂了k科能获得的最大分数
voidsolve(){ cin >> n; for (int i = 1; i <= n; i++) { string str; cin >> str; id[str] = i; } cin >> m; for (int i = 1; i <= m; i++) { string str; int xx, yy; cin >> str >> xx >> yy; v[id[str]].push_back((node){xx, yy}); } cin >> t >> p; memset(f, 0, sizeof(f)); memset(dp, -0x3f, sizeof(dp)); for (int i = 1; i <= n; i++) { // 01背包计算f for (int j = 0; j < v[i].size(); j++) { for (int k = t; k >= v[i][j].y; k--) { f[i][k] = max(f[i][k], f[i][k - v[i][j].y] + v[i][j].x); f[i][k] = min(f[i][k], 100); } } } dp[0][0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = t; j; j--) { for (int k = t; k >= j; k--) { for (int l = 0; l <= p; l++) { if (f[i][j] >= 60) dp[i][k][l] = max(dp[i][k][l], dp[i-1][k-j][l] + f[i][j]); elseif (l) dp[i][k][l] = max(dp[i][k][l], dp[i-1][k-j][l-1] + f[i][j]); } } } } int ans = -1; for (int i = 1; i <= t; i++) { for (int j = 0; j <= p; j++) { ans = max(ans, dp[n][i][j]); } } cout << ans << endl; id.clear(); for (int i = 1; i <= n; i++) v[i].clear(); }
intmain(){ ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { solve(); } return0; }