原题: ZOJ 3769 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3769

一个带有一些限制的背包问题。

假设在没有限制的情况下,那么定义:dp[i][j]表示在前 i 类物品中,总的Toughness为 j 的时候最大的伤害值。

取到第K类的第x个物品时(属性值为D,T),则有转移方程: dp[K][j+T] = max(dp[K][j+T],dp[K-1][j]+D) .其中j+T超过m时按m算就可以了。

但是有限制如下:

1、对于两个手指的,无论是只装备一根手指,还是装备了两只,都用手指这一类来表示,那么,所有手指装备本身当作只装备一根手指,装备两只的两两枚举一下

2、对于Weapon和Shield两种道具以及Two-Handed,我们还是把它们当成一种来处理,首先各自肯定当成一件物品,然后就是枚举Weapon和Shield的搭配了当成一种,将这些归为一类

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
#define N 50007 string god[] = {"Head", "Shoulder", "Neck", "Torso", "Hand", "Wrist", "Waist", "Legs", "Feet", "Finger", "Shield", "Weapon", "Two-Handed"}; struct Good
{
int damag,tough;
Good(int _damg,int _togh)
{
damag = _damg;
tough = _togh;
}
Good(){}
}; vector<Good> G[]; int getnum(string ka)
{
for(int i=;i<;i++)
{
if(god[i] == ka)
return i;
}
} int dp[][N]; int main()
{
int i,j,k;
string ss;
int t,n,m;
int damag,tough;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(i=;i<=;i++)
G[i].clear();
for(i=;i<n;i++)
{
cin>>ss;
scanf("%d%d",&damag,&tough);
k = getnum(ss);
G[k].push_back(Good(damag,tough));
if(k == || k == ) //weapon or sheild,一并算在Two_handed里面
G[].push_back(Good(damag,tough));
}
//枚举weapon and sheild 's combination
for(i=;i<G[].size();i++)
for(j=;j<G[].size();j++)
G[].push_back(Good(G[][i].damag+G[][j].damag,G[][i].tough+G[][j].tough));
G[].clear();
G[].clear();
//G[10] 存放finger所有的情况(单独和组合)
for(i=;i<G[].size();i++)
{
G[].push_back(G[][i]);
for(j=i+;j<G[].size();j++)
G[].push_back(Good(G[][i].damag+G[][j].damag,G[][i].tough+G[][j].tough));
}
G[].clear(); //注意清空,情况都加到G[10]里面去了
memset(dp,-,sizeof(dp));
dp[][] = ;
int T,D;
for(i=;i<G[].size();i++)
{
Good g = G[][i];
T = min(g.tough,m);
dp[][T] = max(dp[][T],g.damag);
}
for(k=;k>=;k--)
{
for(i=;i<=m;i++)
{
dp[k][i] = max(dp[k][i],dp[k+][i]);
if(dp[k+][i] == -)
continue;
for(j=;j<G[k].size();j++)
{
Good g = G[k][j];
T = min(g.tough+i,m);
D = g.damag+dp[k+][i];
dp[k][T] = max(dp[k][T],D);
}
}
}
printf("%d\n",dp[][m]);
}
return ;
}

2014 Super Training #7 C Diablo III --背包问题(DP)的更多相关文章

  1. 2014 Super Training #10 D 花生的序列 --DP

    原题: FZU 2170 http://acm.fzu.edu.cn/problem.php?pid=2170 这题确实是当时没读懂题目,连样例都没想通,所以没做了,所以还是感觉这样散漫的做不好,有些 ...

  2. 2014 Super Training #8 C An Easy Game --DP

    原题:ZOJ 3791 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3791 题意:给定两个0-1序列s1, s2,操作t ...

  3. 2014 Super Training #1 B Fix 状压DP

    原题: HDU 3362 http://acm.hdu.edu.cn/showproblem.php?pid=3362 开始准备贪心搞,结果发现太难了,一直都没做出来.后来才知道要用状压DP. 题意: ...

  4. 2014 Super Training #8 B Consecutive Blocks --排序+贪心

    当时不知道怎么下手,后来一看原来就是排个序然后乱搞就行了. 解法不想写了,可见:http://blog.csdn.net/u013368721/article/details/28071241 其实就 ...

  5. 2014 Super Training #8 A Gears --并查集

    题意: 有N个齿轮,三种操作1.操作L x y:把齿轮x,y链接,若x,y已经属于某个齿轮组中,则这两组也会合并.2.操作Q x y:询问x,y旋转方向是否相同(等价于齿轮x,y的相对距离的奇偶性). ...

  6. 2014 Super Training #9 E Destroy --树的直径+树形DP

    原题: ZOJ 3684 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3684 题意: 给你一棵树,树的根是树的中心(到其 ...

  7. 2014 Super Training #9 C E - Cup 2 --记忆化搜索

    原题:ZOJ 3681 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3681 题意:给一个m,n,m表示m个人,可以把m个 ...

  8. 2014 Super Training #6 H Edward's Cola Plan --排序+二分

    原题: ZOJ 3676  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3676 题意:给每个朋友一瓶可乐,可乐有普通和高 ...

  9. 2014 Super Training #7 F Power of Fibonacci --数学+逆元+快速幂

    原题:ZOJ 3774  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3774 --------------------- ...

随机推荐

  1. 一个小笔记(7):EN_1

    For nearly ten years, the Unified Modeling Language(UML) has been the industry standard for visualiz ...

  2. mongodb driver c#语法

    Definitions and BuildersThe driver has introduced a number of types related to the specification of ...

  3. NLog 自定义字段 写入 oracle

    1.通过Nuget安装NLog 下载,简单入门 请参照 我刚才转的几篇文章,下面我直接贴代码 2.建表语句 create table TBL_LOG ( id ) not null, appname ...

  4. Force.com微信开发系列(五)自定义菜单进阶及语音识别

    在上文里我们介绍了如何通过Force.com平台里为微信账号添加自定义菜单,本文里我们将进一步介绍如何查询菜单以及删除菜单的相关知识,最后会介绍微信平台如何进行语音识别的相关技术. 查询菜单 与创建菜 ...

  5. 2015年第2本(英文第1本):《The Practice of Programming》

    2015年计划透析10本英文原著,最开始选定的第一本英文书是<Who Moved my Cheese>,可是这本书实在是太短.太简单了,总体的意思就是要顺应变化,要跳出自己的舒适区,全文不 ...

  6. iOS 视频播放 - YVideoPlayer - UIView

    这是一个使用简便的视频播放框架,它基于UIView,它可以是一个小窗口,也可以是一个全屏的窗口 简单的方式加载Video框架: 一行代码加载! 一行代码更新! 下载链接 : https://githu ...

  7. 本地预览图片html和js例子

    本地预览图片html和js例子,直接上代码吧. <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" ...

  8. Android群英传笔记系列三 view的自定义:实现一个模拟下载

    1.实现效果:动态显示进度(分别显示了整个的动态改变的过程,然后完成后,弹出一个对话框)       2.实现过程:可以分为绘制一个圆,圆弧和文本三部分,然后在MainAcitivity中通过线程模拟 ...

  9. IOS UILabel 根据内容自适应高度

    iOS Label 自适应高度  适配iOS7以后的版本 更多 self.contentLabelView = [[UILabel alloc] init]; self.contentLabelVie ...

  10. InfluxDB数据备份与恢复

    数据备份与恢复 Example:(192.167.8.13 InfluxDB:DeviceHistory备份到192.167.8.52,然后恢复到该服务器上)   steps:   login 192 ...