描述

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

题意:给出13类装备,每种装备都有攻击力和防御值,每种装备只允许选择一个,13种装备里如果选择了双手装备,就不能选择武器和护盾了,还有戒指可以双手各带一个,求满足防御值至少在M的情况下,攻击力最大为多少。

解题思路:设dp[i][j]为前i种装备,防御值达到j的时候的最大攻击力。那么可以有dp[i][j + t] = max(dp[i][j + t], dp[i - 1][j] + d)这里dp[i - 1][j]不等于-1,也就是必须先能达到这个防御值。可以把武器和护盾单独作为一件双手装备或者把两者合起来组合成一个双手装备。选择单个戒指就相当于只有一只手戴戒指,把戒指两两组合起来也就相当于双手都带了戒指。不过这里的M比较大,直接从第一类装备开始递推可能会超时,由于种类之间没有关系所以从哪个种类开始递推都没有关系,所以可以倒着来推,把数量较大的种类作为递推起点,可以省下很多时间。还有这里用一维可能会出问题,代码中当k=m=kk时可能会同类取了多个

转载自博客:https://blog.csdn.net/a664607530/article/details/70216835

#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(DP)的更多相关文章

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

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

  2. ZOJ 4027 Sequence Swapping(DP)题解

    题意:一串括号,每个括号代表一个值,当有相邻括号组成()时,可以交换他们两个并得到他们值的乘积,问你最大能得到多少 思路:DP题,注定想得掉头发. 显然一个左括号( 的最远交换距离由他右边的左括号的最 ...

  3. ZOJ 3769 Diablo III

    描述 Diablo III is an action role-playing video game. A few days ago, Reaper of Souls (ROS), the new e ...

  4. ZOJ 2625 Rearrange Them(DP)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1625 题目大意:将n个数重新排列,使得每个数的前一个数都不能和之前的 ...

  5. ZOJ 2745 01-K Code(DP)(转)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1745 题目大意:一个串由N个字符组成,每个字符是‘0’或者是‘1’, ...

  6. ZOJ 1013 Great Equipment(DP)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=13 题目大意:说的是有三种不同的装备,分别是头盔,盔甲,战靴需要运输, ...

  7. LightOJ1017 Brush (III)(DP)

    题目大概说一个平面上分布n个灰尘,现在要用一个宽w的刷子清理灰尘:选择一个起点,往水平线上扫过去这个水平线上的灰尘就消失了.问最多进行k次这样的操作能清理最多多少灰尘. 没什么的DP. 先按垂直坐标给 ...

  8. ZOJ 3211 Dream City(DP)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3374 题目大意:JAVAMAN 到梦幻城市旅游见到了黄金树,黄金树上 ...

  9. ZOJ 2702 Unrhymable Rhymes(DP)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1702 题目大意:给定有很多数字组成的诗,譬如 “AABB”, “AB ...

随机推荐

  1. gulp.基础

    1.安装 全局安装 npm install --global gulp 作为项目的开发依赖安装 npm install gulp --save-dev 2.在根目录下创建一个名为gulpfile.js ...

  2. vue-fetch

    1.安装命令“ cnpm install --save isomorphic-fetch es6-promise 2.由于ie不支持Promise,所以需要安装promise-polyfill; cn ...

  3. kotlin学习笔记-异常好玩的list集合总结

    不积跬步无以至千里,不积小流无以成江海 先看看Kotlin中for循环的遍历 fun testList(){ var StringVal = "12_12_13_15_a_b_c_d_yu_ ...

  4. python1114string_test

    #! -*- coding:utf-8 -*- str = "self_learn"print(type(str))str.title()print(str.title()) # ...

  5. 软件测试-历史bug回顾(持续更新~)

    1.第一次编写程序的时候非常不容易看出的错误就是 = 和 == 的区别. 赋值符号,判断符号之间有着天差地别.导致一直循环错误,一直苦苦找寻愿意无果,一步步看代码解决. 2.对于终结条件判断不是很清楚 ...

  6. 纯css使用线性渐变实现滚动进度条(来自于微信前端早读课)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. Datagrip导入导出为一个sql文件详细说明 (mysql)

    Datagrip导入导出为一个sql文件详细说明 导出: (我的无法截图, 借用一张) 导入: (我的无法截图, 再借用一张) 完

  8. python 自动获取手机短信验证码

    需要一个有权限的 APK 在手机实时存储短信到手机内存 /sdcard/smslog.txt 里(外部SD卡也可以知道能通过adb命令访问到): /***** ...... try {long tim ...

  9. C++ Primer 笔记——迭代器

    iostream迭代器 1.虽然iostream类不是容器,但是标准库定义了可以用于IO的迭代器.创建一个流迭代器的时候必须指定要读写的类型.我们可以对任何具有输入运算符(>>)的类型定义 ...

  10. cPanel中添加设置附加域(Addon domain)

    本文介绍cPanel设置附加域(addon domain)来实现一个空间做多个网站的方法. 附加域(addon domain) 作用:通过它可以实现添加 新的顶级域名绑定到主机,从而创建新的站点.例如 ...