ZOJ - 3769 Diablo III (多组dp)
Diablo III is an action role-playing video game. A few days ago, Reaper of Souls (ROS), the new expansion of Diablo III, has been released! On hearing the news, the crazy video game nerd Yuzhi shouted: "I'm so excited! I'm so excited! I wanna kill the Diablo once more!"
The ROS introduced a lot of new features and changes. For example, there are two new attributes for players in the game: Damage and Toughness. The attribute Damage indicates the amount of damage per second you can deal and the Toughness is the total amount of raw damage you can take.
To beat the Diablo, Yuzhi need to select the most suitable equipments for himself. A player can carry at most 13 equipments in 13 slots: Head, Shoulder, Neck, Torso, Hand, Wrist, Waist, Legs, Feet, Shield, Weapon and 2 Fingers. By the way, there is a special type of equipment: Two-Handed. A Two-Handed equipment will occupy both Weapon and Shield slots.
Each equipment has different properties on Damage and Toughness, such as a glove labeled "30 20" means that it can increase 30 Damage and 20 Toughness for the player who equips it in the Hand slot. The total Damage and Toughness is the sum of Damage and Toughness of all equipments on the body. A player without any equipments has 0 Damage and 0 Toughness.
Yuzhi has N equipments stored in his stash. To fight against the Diablo without lose the battle, he must have at least M Toughness. In addition, he want to finish the battle as soon as possible. That means the Damage should be as much as possible. Please help Yuzhi to determine which equipments he should take.
Input
There are multiple test cases. The first line of input is an integer T indicates the number of test cases. For each test case:
The first line contains 2 integers N (1 <= N <= 300) and M (0 <= M <= 50000). The next N lines are the description of equipments. The i-th line contains a string Siand two integers Di and Ti (1 <= Di, Ti <= 50000). Si is the type of equipment in {"Head", "Shoulder", "Neck", "Torso", "Hand", "Wrist", "Waist", "Legs", "Feet", "Finger", "Shield", "Weapon", "Two-Handed"}. Di and Ti are the Damage and Toughness of this equipment.
Output
For each test case, output the maximum Damage that Yuzhi can get, or -1 if he can not reach the required Toughness.
Sample Input
2 1 25 Hand 30 20 5 25 Weapon 15 5 Shield 5 15 Two-Handed 25 5 Finger 5 10 Finger 5 10
Sample Output
-1 35
每个位置上有一堆物品,求最佳的组合方式使防御力大于等于m的情况下攻击力最大。
如果没有限制条件的话这个就是一个普通的dp,但是存在着两个特殊请况::
1.如果选择(双手武器),那么就不能拿双手上的武器(剑和盾?)。
2.还有就是戒指可以带两个。
这样的话我们可以将这两种情况下的所有可能分别化为独特的两组集进行dp就好了(所有可能的武器选择作为一组,所有可能的戒指装戴情况算作一组)
#include <bits/stdc++.h>
using namespace std;
const int maxn = 15;
const int maxm = 60000;
struct *** {
int atk, def;
***(int a, int b) {
this->atk = a; this->def = b;
}
};
map<string, int>mp;
int sum[maxn];
vector<***>G[maxn];
int n, m, dp[maxn][maxm];
bool cmp(int a, int b) {
return G[a].size() > G[b].size();
}
void init() {
mp["Weapon"] = 1;mp["Shield"] = 2;mp["Two-Handed"] = 3;
mp["Finger"] = 4;mp["Feet"] = 5;mp["Legs"] = 6;mp["Waist"] = 7;
mp["Wrist"] = 8;mp["Hand"] = 9;mp["Torso"] = 10;
mp["Neck"] = 11;mp["Shoulder"] = 12;mp["Head"] = 13;
for (int s = 1; s <= 13; s++)
sum[s] = s;
}
void solve() {
dp[2][0] = 0;
for (int s = 3; s <= 13; s++) {
int x = sum[s];
for (int i = m; i >= 0; i--) {
dp[s][i] = max(dp[s][i], dp[s - 1][i]);
if (dp[s - 1][i] == -1)continue;
for (int j = 0; j < G[x].size(); j++) {
*** t = G[x][j];
int d = min(m, i + t.def);
dp[s][d] = max(dp[s][d], dp[s - 1][i] + t.atk);
}
}
}
}
int main() {
init();
int te; scanf("%d", &te);
while (te--) {
memset(dp, -1, sizeof dp);
for (int i = 1; i <= 13; i++) G[i].clear();
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
char m[20]; scanf("%s", m);
int v = mp[m];
int a, b; scanf("%d%d", &a, &b);
G[v].push_back(***(a, b));
}
for (int i = 1; i <= 2; i++)
for (int j = 0; j < G[i].size(); j++)
G[3].push_back(G[i][j]);
for (int i = 0; i < G[1].size(); i++)
for (int j = 0; j < G[2].size(); j++)
G[3].push_back(***(G[1][i].atk + G[2][j].atk, G[1][i].def + G[2][j].def));
int t = G[4].size();
for (int i = 0; i < t; i++) {
for (int j = i + 1; j < t; j++) {
if (i == j)continue;
G[4].push_back(***(G[4][i].atk + G[4][j].atk, G[4][i].def + G[4][j].def));
}
}
sort(sum + 3, sum + 14, cmp);
solve();
cout << dp[13][m] << endl;
}
}
/*
2
5 25
Weapon 15 5
Shield 5 15
Two-Handed 25 5
Finger 5 10
Finger 5 10
*/