Spell Boost

时间限制: 1 Sec  内存限制: 128 MB

题目描述

Shadowverse is a funny card game. One day you are playing a round of this game.
You have n cards, each with two attributes wi and xi. If you use card i, you will cost wi points of power and cause xi damage to the enemy.
Among them, there are two special types of cards: some cards are magic cards and some have “spell boost effect”. Everytime you have used a magic card, for each unused “spell boost effect” card i: if the the current cost of i (i.e. wi) is positive, then wi will be reduced by 1. Note that some cards may be both magic cards and have spell boost effect.
Now you have W points of power, you need to calculate maximum total damage you can cause.

输入

Input is given from Standard Input in the following format:
n W
w1 x1 is_magic1 is_spell_boost1
w2 x2 is_magic2 is_spell_boost2
.
.
wn xn is_magicn is_spell_boostn
Constraints
1 ≤ n ≤ 500
0 ≤ W, wi, xi ≤ 500, and all of them are integers.
is_magici means: If this card is magic card, the value is 1, otherwise the value is 0.
is_spell_boosti means: If this card has spell boost effect, the value is 1, otherwise 0

输出

One integer representing the maximum total damage.

样例输入

3 3
3 3 1 1
2 3 1 1
1 3 1 1

样例输出

9

题意:有n张卡片,每个卡片有一个价值和花费,而且有A,B两种属性,若使用了A属性的卡片就会使手中B属性的卡片花费减少1,问总花费不超过W时的最大价值。
做法:若去掉属性就是一个背包问题,因此这里我们再加一维状态来表示已经用了多少张A属性的卡片。即dp[i][j][k]表示用了前i张卡片,花费不超过j,已经用了k张A属性卡片的最大价值。
三维空间太大,所以要用滚动数组优化。而且要注意循环j和k的时候要从大到小遍历,这是为了保证每次状态都只会从上一张卡片的状态转移过来。(和背包转移的思想类似)。
#include<bits/stdc++.h>
#define N 505
using namespace std;
int dp[N][N]={}; struct ss
{
int x,w,is_magic,is_boost; bool operator < (const ss &s) const
{
if(is_magic!=s.is_magic)return is_magic>s.is_magic;
if(is_boost!=s.is_boost)return is_boost<s.is_boost;
return w<s.w;
} };
ss arr[N]; int main()
{
int n,W;
int x[N],w[N],is_magic[N],is_boost[N]; scanf("%d %d",&n,&W);
for(int i=;i<=n;i++)scanf("%d %d %d %d",&arr[i].w,&arr[i].x,&arr[i].is_magic,&arr[i].is_boost); sort(arr+,arr++n); for(int i=;i<=n;i++)
{
if(arr[i].is_magic)
{
for(int k=i;k>=;k--)
for(int j=W;j>=;j--)
{
if(arr[i].is_boost&&j-max(,arr[i].w-(k-))>=)dp[j][k]=max(dp[j][k], k->= ? dp[j-max(,arr[i].w-(k-))][k-]+arr[i].x :);
else
if(!arr[i].is_boost&&j-arr[i].w>=)dp[j][k]=max(dp[j][k],k->= ? dp[j-arr[i].w][k-]+arr[i].x : );
}
}
else
{
for(int k=i;k>=;k--)
for(int j=W;j>=;j--)
{
if(arr[i].is_boost&&j-max(,arr[i].w-(k))>=)dp[j][k]=max(dp[j][k],dp[j-max(,arr[i].w-(k))][k]+arr[i].x);
else
if(!arr[i].is_boost&&j-arr[i].w>=)dp[j][k]=max(dp[j][k],dp[j-arr[i].w][k]+arr[i].x);
}
}
} int ans=;
for(int i=;i<=n;i++)ans=max(ans,dp[W][i]);
printf("%d\n",ans);
return ;
}
 

Spell Boost的更多相关文章

  1. HDOJ 6508 Problem I. Spell Boost (01背包/DP)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6508 题目: Problem Description Shadowverse is a funny car ...

  2. 2018年东北地区赛S - Problem I. Spell Boost HDU - 6508

    题目地址:https://vjudge.net/problem/HDU-6508 思路:给一些卡,分为四种卡.1.白卡(没效果)2.魔法,作用卡(会对作用卡的费用减少,也会被魔法卡作用)3.作用卡(会 ...

  3. 2018 东北地区大学生程序设计竞赛(ABEHIK)

    HDU6500:Problem A. Game with string 题意: 给你一个字符串s以及它的m个子串的首尾位置,现在Alice和 Bob两个人轮流在任一子串的前面或者后面加1个字符,要求加 ...

  4. boost强分类器的实现

    boost.cpp文件下: bool CvCascadeBoost::train( const CvFeatureEvaluator* _featureEvaluator, int _numSampl ...

  5. Boost信号/槽signals2

    信号槽是Qt框架中一个重要的部分,主要用来解耦一组互相协作的类,使用起来非常方便.项目中有同事引入了第三方的信号槽机制,其实Boost本身就有信号/槽,而且Boost的模块相对来说更稳定. signa ...

  6. 玩转Windows服务系列——使用Boost.Application快速构建Windows服务

    玩转Windows服务系列——创建Windows服务一文中,介绍了如何快速使用VS构建一个Windows服务.Debug.Release版本的注册和卸载,及其原理和服务运行.停止流程浅析分别介绍了Wi ...

  7. boost::function的用法

    本片文章主要介绍boost::function的用法. boost::function 就是一个函数的包装器(function wrapper),用来定义函数对象. 1.  介绍 Boost.Func ...

  8. Boost条件变量condition_variable_any

    Boost条件变量可以用来实现线程同步,它必须与互斥量配合使用.使用条件变量实现生产者消费者的简单例子如下,需要注意的是cond_put.wait(lock)是在等待条件满足.如果条件不满足,则释放锁 ...

  9. 新手,Visual Studio 2015 配置Boost库,如何编译和选择,遇到无法打开文件“libboost_thread-vc140-mt-gd-1_63.lib“的解决办法

    1,到官网下载最新的boost,www.boost.org 这里我下载的1-63版本. 2,安装,解压后运行bootstrap.bat文件.稍等一小会就OK. 3,编译boost库.注意一定要使用VS ...

随机推荐

  1. office word excel等图标显示异常

    1.查看注册表:查看参数对应的路径被删除,计算机搜索新的文件路径更改路径即可.以此类推~ 计算机\HKEY_CLASSES_ROOT\Excel.Sheet.12\DefaultIcon 正常exce ...

  2. 如何启动Intel VT-x

    如何启动Intel VT-x 5 在64bit win7系统下安装了Vmware10,然后安装64位的UbuntuKylin 14.04,想要打开UbuntuKylin,弹出如下对话框: 请问该如何启 ...

  3. 数学题 追及相遇—HDOJ1275 人傻需要多做题

    两车追及或相遇问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  4. Bootstrap历练实例:大的按钮

    <!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...

  5. 变色龙启动MAC时,错误信息“ntfs_fixup: magic doesn't match:”的解决办法

    如下是变色龙启动的bdmesg,解决办法就是用mac的磁盘管理器,对ntfs分区进行检验修复.需要安装ntfs的驱动支持. 实在不行,就删除调整过大小的分区,重新用Windows的磁盘管理器重新分区. ...

  6. Java输入几行字符串

    查找书籍 给定n本书的名称和定价,本题要求编写程序,查找并输出其中定价最高和最低的书的名称和定价. 输入格式: 输入第一行给出正整数n(<10),随后给出n本书的信息.每本书在一行中给出书名,即 ...

  7. CSS 布局经典问题初步整理

    CSS 定位问题 主要就是经典的绝对定位,相对定位问题. 10个文档学布局:通过十个例子讲解布局,主要涉及相对布局,绝对布局,浮动. 百度前端学院笔记 – 理解绝对定位:文章本身一般,几篇参考文献比较 ...

  8. 使用VMware克隆出来的新虚拟机无法联网-问题解决记录

    背景: 使用VMware克隆出来的新虚拟机无法联网,重启网卡出现如下图提示: 继续输入#ifup ens33 提示: ens33: unknown interface: No such device ...

  9. (转)iOS 最佳实践

    本文转自http://www.jianshu.com/p/b0bf2368fb95 感谢作者和译者 iOS最佳实践 iOS最佳实践 译者注 本文翻译自 futurice 公司的 iOS Good Pr ...

  10. 牛客网暑期ACM多校训练营(第五场) E room(最小费用最大流 , 最小权二分图匹配模板)

    链接: https://www.nowcoder.com/acm/contest/143/E 题意: 给定n个宿舍的新安排, 每个宿舍都有4个人, 问要至少有多少个人换位才能变成新安排. 可以建一个二 ...