原题: 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. 安装性能测试工具:sysbench和使用apache的ab

    一.软件的用途,它主要包括以下几种方式的测试:1.cpu性能2.磁盘io性能3.调度程序性能4.内存分配及传输速度5.POSIX线程性能6.数据库性能(OLTP基准测试) 这个软件为什么找不到官网呢? ...

  2. SPJS Upload for SharePoint: Custom upload page for uploading documents to various document libraries in a site collection

    http://spjsblog.com/2013/12/08/spjs-upload-for-sharepoint-custom-upload-page-for-uploading-documents ...

  3. 桥牌笔记 Skill Level 4 C7 小心将吃

    南主打5H. 看来问题不大,但要小心南的方块AK会阻塞桥路. 如果方块3-2分布,并且将牌也3-2分布,就很容易. 如果红桃4-1分布,那是死定了. 如果方块4-1分布,还有希望完成的! 为了防止东家 ...

  4. android 回调函数一:基本概念

    1.概念 客户程序C调用服务程序S中的某个函数A,然后S又在某个时候反过来调用C中的某个函数B,对于C来说,这个B便叫做回调函数. 一般说来,C不会自己调用B,C提供B的目的就是让S来调用它,而且是C ...

  5. Struts2(十)OGNL标签二与Struts2标签

    一.Struts2标签的优势 标签库简化了用户对标签的使用 结合OGNL使用,对于集合.对象的访问功能非常强大 提供可扩展的主题.模板支持.极大简化了视图页面的编写 不依赖任何表现层技术 Struts ...

  6. 【原】自定义UINavigationItem的两种方法以及相应的隐藏方法

    第一种: UIImage *searchimage=[UIImage imageNamed:@"search.png"]; UIBarButtonItem *barbtn=[[[U ...

  7. HTTP通信过程底层实现原理

  8. git常用命令,git版本控制和Xcode结合使用,用Xcode提交到github,github客户端使用

    1.git常用命令 查看命令: 1.git --help 查看git所有命令 2.git clone -help 查看git clone命令的细节 3.git config -l   查看当前所有配置 ...

  9. windows 和 linux ssh互连

    从windows连接到linux: linux开启sshd服务即可,主要是windows的配置如下: 1.使用软件,putty可以直接使用 2.使用cmd控制台连接linux,安装SSH Secure ...

  10. 三种另外的循环 while{} 和do{}while{}还有switch case

    while的写法 var i=0; while(i<5){ document.write("12378<br />");  i++;} while(true)-- ...