描述

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.

输入

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.

输出

For each test case, output the maximum Damage that Yuzhi can get, or -1 if he can not reach the required Toughness.

样例输入

2
1 25
Hand 30 20
5 25
Weapon 15 5
Shield 5 15
Two-Handed 25 5
Finger 5 10
Finger 5 10

样例输出

-1
35
 #include <stdio.h>
#include <string>
#include <map>
#include <vector>
#include <iostream>
#define MAXN 310
using namespace std; int n,m;
map< string , int > M; int max(int a, int b){
if(a>b)return a;
else return b;
} void init(){
M["Head"]=;
M["Shoulder"]=;
M["Neck"]=;
M["Torso"]=;
M["Hand"]=;
M["Wrist"]=;
M["Waist"]=;
M["Legs"]=;
M["Feet"]=;
M["Shield"]=;//finger
M["Weapon"]=;
M["Finger"]=;
M["Two-Handed"]=;
} struct Node
{
int d,t;
}nod; vector<Node> V[];//存储同类物品
int dp[][];
int vd,vt; void read(){
int i,j,d,t;
char ch[];
scanf("%d %d" ,&n ,&m);
for(i=; i<; i++){
V[i].clear();
}
for(i=; i<n; i++){
scanf("%s %d %d" ,ch , &d ,&t);
int index=M[string(ch)];
nod.d=d;
nod.t=t;
V[index].push_back( nod );
if(index== || index==){
V[].push_back( nod );
}
}
//两只手的装备
for(i=; i<V[].size(); i++){
for(j=; j<V[].size(); j++){
nod.d=V[][i].d+V[][j].d;
nod.t=V[][i].t+V[][j].t;
V[].push_back( nod );
}
}
//存戒指
V[].clear();
for(i=; i<V[].size(); i++){
V[].push_back( V[][i] );
for(j=i+; j<V[].size(); j++){
nod.d=V[][i].d+V[][j].d;
nod.t=V[][i].t+V[][j].t;
V[].push_back( nod );
}
}
V[].clear();
} int main(){
init();
int t;
int i,j,k;
scanf("%d" ,&t);
while( t-- ){
read();
memset(dp,-,sizeof(dp));
//12单独处理一下,存到9
dp[][]=;
for(i=; i<V[].size(); i++){
nod=V[][i];
if(nod.t>m){
vt=m;
}else{
vt=nod.t;
}
vd=nod.d;
dp[][vt]=max( dp[][vt] , vd );
}
for(k=; k>=; k--){
for(j=; j<=m; j++){
dp[k][j]=max( dp[k][j],dp[k+][j] );
if( dp[k+][j]==- )continue;
/*
dp[k][j] 表示k件装备,它所用的防御是j的伤害
当前装备伤害+之前伤害最大值
dp[k][vt]=max( dp[k][vt], nod.d+dp[k+1][j] )
*/
for(i=; i<V[k].size(); i++){
nod=V[k][i];
if( nod.t +j > m ){
vt=m;
}else{
vt=nod.t +j;
}
dp[k][vt]=max( dp[k][vt], nod.d+dp[k+][j] );
}
}
}
printf("%d\n" ,dp[][m]);
}
return ;
}

ZOJ 3769 Diablo III的更多相关文章

  1. ZOJ 3769 Diablo III(分组背包)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3769 题意:有13种装备,每种装备值可以穿戴一种,特殊的就是双手武器和单手 ...

  2. 2014 Super Training #7 C Diablo III --背包问题(DP)

    原题: ZOJ 3769 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3769 一个带有一些限制的背包问题. 假设在没有限 ...

  3. 转化为分组背包 zoj 3769

    题目链接:https://vjudge.net/problem/ZOJ-3769 题意:现在你要去打怪,你有13种装备,每件装备会有伤害和防御两种属性,一般来说,每种装备只可以装备一件,但是特别的,戒 ...

  4. 【转载】ACM总结——dp专辑

    感谢博主——      http://blog.csdn.net/cc_again?viewmode=list       ----------  Accagain  2014年5月15日 动态规划一 ...

  5. 【DP专辑】ACM动态规划总结

    转载请注明出处,谢谢.   http://blog.csdn.net/cc_again?viewmode=list          ----------  Accagain  2014年5月15日 ...

  6. dp专题训练

    ****************************************************************************************** 动态规划 专题训练 ...

  7. 【DP专辑】ACM动态规划总结(转)

    http://blog.csdn.net/cc_again/article/details/25866971 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间效率高,代码量少,多元性强, ...

  8. dp有哪些种类

    dp有哪些种类 一.总结 一句话总结: 二.dp动态规划分类详解 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间效率高,代码量少,多元性强,主要考察思维能力.建模抽象能力.灵活度. * ...

  9. (转)dp动态规划分类详解

    dp动态规划分类详解 转自:http://blog.csdn.NET/cc_again/article/details/25866971 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间 ...

随机推荐

  1. Middleware / 中间件

    中间件格式 module.exports = options => { return (ctx, next) => { // do something } } 中间件格式为一个高阶函数,外 ...

  2. 《T-SQL查询》- SQL逻辑处理

    下面列出SQL查询语句的一般形式,以及各个子句被逻辑处理的顺序步骤: (8) SELECT (9) DISTINCT (11) <TOP_specification> <select ...

  3. 谷歌三大核心技术(一)Google File System中文版

    http://www.open-open.com/lib/view/open1328763454608.html

  4. CentOS7 关闭防火墙[转]

    CentOS6关闭防火墙使用以下命令, /临时关闭 service iptables stop //禁止开机启动 chkconfig iptables off CentOS7中若使用同样的命令会报错, ...

  5. c#设计模式之:外观模式(Facade)

    一.引言 在软件开发过程中,客户端程序经常会与复杂系统的内部子系统进行耦合,从而导致客户端程序随着子系统的变化而变化,然而为了将复杂系统的内部子系统与客户端之间的依赖解耦,从而就有了外观模式,也称作 ...

  6. 导出包含图片的excel、word、pdf 笔记

    /** * 导出word * @throws Exception */ @Override public byte[] WordExport( List<VbLibGlobalAnalyList ...

  7. 爬虫开发5.requests模块的cookie和代理操作

    代理和cookie操作 一.基于requests模块的cookie操作 引言:有些时候,我们在使用爬虫程序去爬取一些用户相关信息的数据(爬取张三“人人网”个人主页数据)时,如果使用之前requests ...

  8. 透明数据加密 (TDE)常见问题解答

    透明数据加密 (TDE)常见问题解答问题任何人只要有权访问加密数据就能对其进行解密吗?TDE 会带来哪些开销?哪些加密算法可与 TDE 一同使用?可以使用第三方加密算法代替 TDE 提供的算法吗?可以 ...

  9. kvm虚拟机磁盘文件读取小结

    kvm虚拟机磁盘挂载还真不是一帆风顺的.xen虚拟化默认就raw格式的磁盘,可以直接挂载,kvm如果采用raw也可以直接挂载,与xen磁盘挂载方式一致. 1.kvm虚拟化相比xen虚拟化来说,工具与方 ...

  10. Windows便签快捷键

    Win+R 是运行的快捷件打 StikyNot 回车 快捷键 功能Ctrl+N 新建一张便笺Ctrl+D 删除当前便笺Ctrl+E 居中对齐Ctrl+R 右对齐Ctrl+J 左对齐Ctrl+I 斜体C ...