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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| #include <iostream> #include <string> #include <sstream> #include <algorithm> using namespace std;
const int MIN_VALUE = -999;
struct Minion { int att = 0; int hp = 0; bool D = false; bool W = false; };
int maxHarm(Minion* minions, int n, int i, int res, bool first) { if (i == n) { if (res >= 8) return 0; else return MIN_VALUE; }
int maxH = 0; if (first) { if (minions[i].W && minions[i].D || minions[i].hp > 8) maxH = max(maxHarm(minions, n, i + 1, res, false) + minions[i].att, maxHarm(minions, n, i + 1, res + minions[i].att, false)); else maxH = maxHarm(minions, n, i + 1, res, false); } else { if (minions[i].W) { maxH = maxHarm(minions, n, i + 1, res, false) + minions[i].att * 2; if (minions[i].D || minions[i].hp > 8) { maxH = max(maxH, maxHarm(minions, n, i + 1, res + minions[i].att, false) + minions[i].att); maxH = max(maxH, maxHarm(minions, n, i + 1, res + minions[i].att * 2, false)); } else maxH = max(maxH, maxHarm(minions, n, i + 1, res + minions[i].att, false)); } else { maxH = max(maxHarm(minions, n, i + 1, res, false) + minions[i].att, maxHarm(minions, n, i + 1, res + minions[i].att, false)); } }
return maxH; }
int main() { int n = 0; while (cin >> n) { Minion* minions = new Minion[n]; string line; getline(cin, line); for (int i = 0; i < n; i++) { getline(cin, line); istringstream sin(line); int att = 0, hp = 0, d = 0, w = 0; sin >> att >> hp; minions[i].att = att; minions[i].hp = hp; char c; while (sin >> c) { if (c == 'D') minions[i].D = true; if (c == 'W') minions[i].W = true; } }
int maxH = 0; for (int i = 0; i < n; i++) { swap(minions[0], minions[i]); maxH = max(maxH, maxHarm(minions, n, 0, 0, true)); } cout << maxH << endl;
delete[] minions; }
return 0; }
|