2014 Super Training #7 C Diablo III --背包问题(DP)
原题: 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)的更多相关文章
- 2014 Super Training #10 D 花生的序列 --DP
原题: FZU 2170 http://acm.fzu.edu.cn/problem.php?pid=2170 这题确实是当时没读懂题目,连样例都没想通,所以没做了,所以还是感觉这样散漫的做不好,有些 ...
- 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 ...
- 2014 Super Training #1 B Fix 状压DP
原题: HDU 3362 http://acm.hdu.edu.cn/showproblem.php?pid=3362 开始准备贪心搞,结果发现太难了,一直都没做出来.后来才知道要用状压DP. 题意: ...
- 2014 Super Training #8 B Consecutive Blocks --排序+贪心
当时不知道怎么下手,后来一看原来就是排个序然后乱搞就行了. 解法不想写了,可见:http://blog.csdn.net/u013368721/article/details/28071241 其实就 ...
- 2014 Super Training #8 A Gears --并查集
题意: 有N个齿轮,三种操作1.操作L x y:把齿轮x,y链接,若x,y已经属于某个齿轮组中,则这两组也会合并.2.操作Q x y:询问x,y旋转方向是否相同(等价于齿轮x,y的相对距离的奇偶性). ...
- 2014 Super Training #9 E Destroy --树的直径+树形DP
原题: ZOJ 3684 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3684 题意: 给你一棵树,树的根是树的中心(到其 ...
- 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个 ...
- 2014 Super Training #6 H Edward's Cola Plan --排序+二分
原题: ZOJ 3676 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3676 题意:给每个朋友一瓶可乐,可乐有普通和高 ...
- 2014 Super Training #7 F Power of Fibonacci --数学+逆元+快速幂
原题:ZOJ 3774 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3774 --------------------- ...
随机推荐
- java ftp
FTPUtil import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import jav ...
- PHP生成图片验证码demo【OOP面向对象版本】
下面是我今天下午用PHP写的一个生成图片验证码demo,仅供参考. 这个demo总共分为4个文件,具体代码如下: 1.code.html中的代码: <!doctype html> < ...
- PHP学习笔记:keditor的使用
keditor时一个免费的开源编辑器,很多公司在使用(百度编辑器也不错).最近为了做一个客户信息管理系统,在发送邮件模块用到这个编辑器,也算学习一下新的东西. 第一步:下载编辑器 到它的官网下载:ht ...
- 中国各城市PM2.5数据间的相关分析
code{white-space: pre;} pre:not([class]) { background-color: white; }if (window.hljs && docu ...
- .NET Core 和 ASP.NET 5 RC1 发布
昨天微软发布了 .NET Core 和 ASP.NET 5 候选版本,支持 Windows,Linux 和 OS X 平台,版本 License 为 "Go Live",,也就是说 ...
- Vue表单
gitHub地址: https://github.com/lily1010/vue_learn/tree/master/lesson11 一 vue表单 实在是太简单了,直接来个例子 <!DOC ...
- 简单几步让Chrome浏览器也能打开Oracle EBS
2016-12-14更新: Google Chrome浏览器从版本45开始正式禁用NPAPI插件(也就是原本JRE插件的实现架构).所以如果你的浏览器版本已经是45以上了,本文提供的方法将不再适用.以 ...
- MyBatis入门(六)---mybatis与spring的整合
一.整合需要 1.1.方法 上一章中的数据 需要spring通过单例方式管理SqlSessionFactory spring和mybatis整合生成代理对象,使用SqlSessionFactory创建 ...
- Android官方多媒体API Mediacodec翻译(一)
因近期工作调整,关于Mediacodec部分的翻译会暂停,后续有时间一定补上,非常抱歉. 本文章为根据Android Mediacodec官方英文版的原创翻译,转载请注明出处:http://www.c ...
- 常用oracle函数
一.逗号拼接字段 SELECT LISTAGG(aa, ',') WITHIN GROUP (ORDER BY aa) AS AA FROM *** where id<5 输出结果例如:1,2, ...