ZOJ 3769-Diablo III(DP)
描述
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)的更多相关文章
- ZOJ 3769 Diablo III(分组背包)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3769 题意:有13种装备,每种装备值可以穿戴一种,特殊的就是双手武器和单手 ...
- ZOJ 4027 Sequence Swapping(DP)题解
题意:一串括号,每个括号代表一个值,当有相邻括号组成()时,可以交换他们两个并得到他们值的乘积,问你最大能得到多少 思路:DP题,注定想得掉头发. 显然一个左括号( 的最远交换距离由他右边的左括号的最 ...
- ZOJ 3769 Diablo III
描述 Diablo III is an action role-playing video game. A few days ago, Reaper of Souls (ROS), the new e ...
- ZOJ 2625 Rearrange Them(DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1625 题目大意:将n个数重新排列,使得每个数的前一个数都不能和之前的 ...
- ZOJ 2745 01-K Code(DP)(转)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1745 题目大意:一个串由N个字符组成,每个字符是‘0’或者是‘1’, ...
- ZOJ 1013 Great Equipment(DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=13 题目大意:说的是有三种不同的装备,分别是头盔,盔甲,战靴需要运输, ...
- LightOJ1017 Brush (III)(DP)
题目大概说一个平面上分布n个灰尘,现在要用一个宽w的刷子清理灰尘:选择一个起点,往水平线上扫过去这个水平线上的灰尘就消失了.问最多进行k次这样的操作能清理最多多少灰尘. 没什么的DP. 先按垂直坐标给 ...
- ZOJ 3211 Dream City(DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3374 题目大意:JAVAMAN 到梦幻城市旅游见到了黄金树,黄金树上 ...
- ZOJ 2702 Unrhymable Rhymes(DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1702 题目大意:给定有很多数字组成的诗,譬如 “AABB”, “AB ...
随机推荐
- 洛谷P3676 小清新数据结构题 [动态点分治]
传送门 思路 这思路好妙啊! 首先很多人都会想到推式子之后树链剖分+线段树,但这样不够优美,不喜欢. 脑洞大开想到这样一个式子: \[ \sum_{x} sum_x(All-sum_x) \] 其中\ ...
- eclipse 安装教程
eclipse 安装教程 一:安装包下载: 链接: https://pan.baidu.com/s/1qZtt62o 密码: 4ak2 注:若 下载链接失效,请看本文公告的QQ群,请联系群主. 二:安 ...
- iOS项目国际化详解
现在的开发中难免会遇到项目国际化处理,下面把我理解到的国际化相关的知识点进行总结归纳 1 首先是对项目名称,系统性的文字进行名字化,比如程序名字 1,先给项目添加语言 2 添加InfoPlist.st ...
- 使用gulp-babel转换Es6出现exports is not defined 问题
//问题描述:当使用import导入模块时,出现exports is not defined //1.安装插件 npm install --save-dev babel-plugin-transfor ...
- LeetCode(124):二叉树中的最大路径和
Hard! 题目描述: 给定一个非空二叉树,返回其最大路径和. 本题中,路径被定义为一条从树中任意节点出发,达到任意节点的序列.该路径至少包含一个节点,且不需要经过根节点. 示例 1: 输入: [1, ...
- 利用vue-cli创建新项目
1.安装vue-cli npm i vue-cli --gd 2.初始化一个项目 vue init webpack test //test 是个项目名称并且配置相应的配置,(测试部份的可以选择no) ...
- String 类的实现(3)String类常用函数
2 #include<iostream> 3 #include<stdio.h> 4 #include<assert.h> 5 #include <iom ...
- labelme连续将文件夹中的json文件进行可视化的指令
for /r C:\Users\Fourmi\Desktop\ZP0 %i in (*.json) do labelme_json_to_dataset %i
- 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
上一篇文章讲述了一个服务如何从配置中心读取文件,配置中心如何从远程git读取配置文件,当服务实例很多时,都从配置中心读取文件,这时可以考虑将配置中心做成一个微服务,将其集群化,从而达到高可用,架构图如 ...
- ASP.NET Core IHostEnvironment和IApplicationLifetime介绍
IHostEnvironment获取程序信息 public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app ...