ZOJ 3769 Diablo III
描述
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的更多相关文章
- ZOJ 3769 Diablo III(分组背包)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3769 题意:有13种装备,每种装备值可以穿戴一种,特殊的就是双手武器和单手 ...
- 2014 Super Training #7 C Diablo III --背包问题(DP)
原题: ZOJ 3769 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3769 一个带有一些限制的背包问题. 假设在没有限 ...
- 转化为分组背包 zoj 3769
题目链接:https://vjudge.net/problem/ZOJ-3769 题意:现在你要去打怪,你有13种装备,每件装备会有伤害和防御两种属性,一般来说,每种装备只可以装备一件,但是特别的,戒 ...
- 【转载】ACM总结——dp专辑
感谢博主—— http://blog.csdn.net/cc_again?viewmode=list ---------- Accagain 2014年5月15日 动态规划一 ...
- 【DP专辑】ACM动态规划总结
转载请注明出处,谢谢. http://blog.csdn.net/cc_again?viewmode=list ---------- Accagain 2014年5月15日 ...
- dp专题训练
****************************************************************************************** 动态规划 专题训练 ...
- 【DP专辑】ACM动态规划总结(转)
http://blog.csdn.net/cc_again/article/details/25866971 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间效率高,代码量少,多元性强, ...
- dp有哪些种类
dp有哪些种类 一.总结 一句话总结: 二.dp动态规划分类详解 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间效率高,代码量少,多元性强,主要考察思维能力.建模抽象能力.灵活度. * ...
- (转)dp动态规划分类详解
dp动态规划分类详解 转自:http://blog.csdn.NET/cc_again/article/details/25866971 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间 ...
随机推荐
- model.find(options)
options {Object} 操作选项,会通过 parseOptions 方法解析 return {Promise} 返回单条数据 查询单条数据,返回的数据类型为对象.如果未查询到相关数据,返回值 ...
- ubuntu 编译安装 mod_wsgi
在编译过程中遇到一些问题,记录下来方便别人使用. step1: 下载.windows下面会有编译好的包,Ubuntu没有需要自己编译. 地址: https://github.com/GrahamDum ...
- RobotFramework与Jenkins集成后失败用例重跑
Jenkins的执行Windows批处理命令填写如下: call pybot.bat -i 1adsInterface 01_测试用例\接口测试用例\adsInterface.txt call pyb ...
- vue的props 属性类似于bug的东西
/* * @Author: shs * @Date: 2019-04-19 17:48:39 * @Last Modified by: shs * @Last Modified time: 2019- ...
- RDLC报表的相关技巧三(数量/金额的逐页累加)
数量/金额的逐页累加,不是当页小计. 核心步骤: 1.在Group1大组中加入小组Group2,2.Group2的组尾加入一个计算框 : =RunningValue(Fields!BaseAmount ...
- 【bzoj 3595】: [Scoi2014]方伯伯的Oj
传送门&& 原题解 蒟蒻终于做到一道方伯伯的题了…… 调了一个上午一直TLE(发现自己打了好久的splay板子竟然是错的这种丢人事情我就不说了) 很明显,要建两棵树,$T1$维护排名, ...
- 剑指offer面试题1---赋值运算符函数
题目描述:如下类型CMyString的声明,请为该类型添加赋值运算符函数. class CMyString{public: CMyString(char* pData = NULL); C ...
- (转)windows下VMware-workstation中安装CentOS
windows下VMware-workstation中安装CentOS windows下VMware-workstation中安装CentOS,可以分两部分,安装虚拟机和安装CentOS虚拟机.具 ...
- React-Native 工程添加推送功能 (iOS 篇)
推送已经是是手机应用的基本功能,如果自己实现一套推送系统费时费力,所有一般我们会使用第三方的推送服务,这里我使用「极光推送」作为集成推送的例子,因为有现成的 react native 插件 jpush ...
- 浅谈Android选项卡(一)
选项卡,这样UI设计在很多方面都存在,window,web,ios,Android. 选项卡的主要作用,不用多介绍,可以在有线的空间内,显示出更多内容,同时也是操作起来也很方便.