1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std;
char name[][100]={"Head", "Shoulder", "Neck", "Torso", "Hand", "Wrist", "Waist", "Legs", "Feet", "Shield", "Weapon", "Two-Handed", "Finger"}; int num[15],d[15][310],t[15][310],dp[15][50010]; char s[100]; int main(int argc, char const *argv[]) { int T,n,m; cin >> T; while (T--){ memset(num,0,sizeof(num)); cin >> n >> m; for (int i = 0; i < n; i ++){ scanf("%s", s); int j; for (j = 0; ;j ++){ if (strcmp(s,name[j]) == 0) break; } j ++; num[j] ++; scanf("%d%d", &d[j][num[j]], &t[j][num[j]]); } memset(dp,-1,sizeof(dp)); dp[0][0] = 0; for (int i = 0; i <= num[13]; i ++){ for (int j = i + 1; j <= num[13]; j ++){ dp[0][min(m,t[13][i] + t[13][j])] = max(dp[0][min(m,t[13][i] + t[13][j])], d[13][i] + d[13][j]); } }
for (int i = 1; i <= 11; i ++){ for (int j = 0; j <= m; j ++){ if (dp[i - 1][j] == -1) continue; for (int k = 0; k <= num[i]; k ++){ dp[i][min(m, j + t[i][k])] = max(dp[i][min(m, j + t[i][k])], dp[i - 1][j] + d[i][k]); } } } for (int j = 0; j <= m; j ++){ if (dp[9][j] == -1) continue; for (int k = 0; k <= num[12]; k ++){ dp[11][min(m, j + t[12][k])] = max(dp[11][min(m, j + t[12][k])], dp[9][j] + d[12][k]); } } printf("%dn",max(-1,dp[11][m])); } return 0; }
|