ZOJ 3769 Diablo III

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 <= DiTi <= 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

分组背包,需要对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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值