ZOJ 3769 Diablo III
来源:互联网 发布:linux环境搭建 编辑:程序博客网 时间:2024/04/29 18:38
Description
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 Si and 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
21 25Hand 30 205 25Weapon 15 5Shield 5 15Two-Handed 25 5Finger 5 10Finger 5 10
Sample Output
-135
分组背包,需要对finger,shield,weapon做特殊处理。
但是因为N*M很大,所以要用二维数组来节省时间。
但是还是会超时,所以要对分组按照元素数量排序,
把最多的来初始化,可以省下很多时间。
#include<cstdio>#include<algorithm>#include<vector>#include<cstring>#include<iostream>#include<string>#include<map>using namespace std;const int maxn = 50005;struct abc{int value, cost;abc(){}abc(int value, int cost) :value(value), cost(cost){}};bool cmp(const vector<abc>&a, const vector<abc>&b){return a.size() > b.size();}abc operator +(const abc&a, const abc&b){return abc(a.value + b.value, a.cost + b.cost);}vector<abc> a[15];map<string, int> M;int n, T, m, x, y, f[12][maxn];string s;void begin(){M["Head"] = 1;M["Shoulder"] = 2;M["Neck"] = 3;M["Torso"] = 4;M["Hand"] = 5;M["Wrist"] = 6;M["Waist"] = 7;M["Legs"] = 8;M["Feet"] = 9;M["Finger"] = 14;M["Shield"] = 12;M["Weapon"] = 13;M["Two-Handed"] = 11;scanf("%d", &T);}void insert(){scanf("%d%d", &n, &m);for (int i = 0; i < 15; i++) a[i].clear();for (int i = 0; i < n; i++){cin >> s >> x >> y;a[M[s]].push_back(abc(x, y));}if (a[14].size() == 1) a[10].push_back(a[14][0]);else{for (int i = 0; i < a[14].size(); i++)for (int j = i + 1; j < a[14].size(); j++)a[10].push_back(a[14][i] + a[14][j]);}if (!a[12].size()){for (int i = 0; i < a[13].size(); i++) a[11].push_back(a[13][i]);}else if (!a[13].size()){for (int i = 0; i < a[12].size(); i++) a[11].push_back(a[12][i]);}else for (int i = 0; i < a[12].size(); i++)for (int j = 0; j < a[13].size(); j++)a[11].push_back(a[12][i] + a[13][j]);}int main(){begin();while (T--){insert();sort(a + 1, a + 12, cmp);memset(f, -1, sizeof(f));for (int i = 0; i < a[1].size(); i++){int cost = min(m, a[1][i].cost);f[1][cost] = max(f[1][cost], a[1][i].value);}for (int i = 2; i <= 11; i++)for (int j = 0; j <= m; j++)if (f[i - 1][j] >= 0){f[i][j] = max(f[i][j], f[i - 1][j]);for (int k = 0; k < a[i].size(); k++){int cost = min(m, j + a[i][k].cost);f[i][cost] = max(f[i][cost], f[i - 1][j] + a[i][k].value);}}cout << f[11][m] << endl;}return 0;}
- ZOJ 3769 Diablo III
- ZOJ 3769 Diablo III
- ZOJ 3769 Diablo III
- ZOJ 3769 Diablo III(DP)
- [dp] zoj 3769 Diablo III
- ZOJ 3769 —— Diablo III(背包,DP)
- zoj 3769 Diablo III (分组背包+优化+背包细节)
- ZOJ 3719 Diablo III 动态规划
- ZOJ 3718 Diablo II
- Diablo III 演示观后
- 为Diablo III 创建Socks5代理
- ZOJ3769-Diablo III(分组背包)
- [ZOJ 3049] Diablo II Items [动态规划]
- ZOJ 3616Choir III
- zoj(Strange Calendar III)
- Strange Calendar III zoj 4011
- ZOJ 3403 Strange Calendar III
- zoj 3403 Strange Calendar III
- http://www.jb51.net/article/41274.htm
- Properties使用方法解析
- 归并排序
- UVa #10163 Storage Keepers (习题9-9)
- Acitivity 之间界面切换动画
- ZOJ 3769 Diablo III
- Ajax jQuery Web聊天室
- 题目1521:二叉树的镜像
- 北向接口/ 南向接口
- 一个完整的Flexbox指南
- GCC和C99标准中的inline
- UIScrollView代码实现循环滚动
- POJ 1004: Financial Management
- 服务器端接收客户端通过socket传递来的对象的ClassNotFoundException异常。