Spell Boost

时间:2022-09-15 09:22:59

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&period; Spell Boost (01背包&sol;DP)

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

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

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

  3. 2018 东北地区大学生程序设计竞赛&lpar;ABEHIK&rpar;

    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信号&sol;槽signals2

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

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

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

  7. boost&colon;&colon;function的用法

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

  8. Boost条件变量condition&lowbar;variable&lowbar;any

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

  9. 新手,Visual Studio 2015 配置Boost库,如何编译和选择,遇到无法打开文件&OpenCurlyDoubleQuote;libboost&lowbar;thread-vc140-mt-gd-1&lowbar;63&period;lib&OpenCurlyDoubleQuote;的解决办法

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

随机推荐

  1. windows调试器尝鲜

    曾几何时,我也下载过看雪论坛精华看的津津有味.可惜一直没有动手去调试,学到的x86汇编指令也忘得差不多了.最近将老机器的T4200 CPU换成了更省电,温度更低的P8800,为了支援新的VT虚拟化,特 ...

  2. byte与char的区别

     byte 是字节数据类型 ,是有符号型的,占1 个字节:大小范围为-128—127 .char 是字符数据类型 ,是无符号型的,占2字节(Unicode码 ):大小范围 是0—65535 :char ...

  3. &lbrack;Solution&rsqb; AOP原理解析及Castle、Autofac、Unity框架使用

    本节目录: AOP介绍 AOP基本原理 AOP框架 Castle Core Castle Windsor Autofac Unity AOP介绍 面向切面编程(Aspect Oriented Prog ...

  4. C&plus;&plus;之内联函数与constexpr

    inline 函数 规模小,流程直接且频繁调用 cout<<shortString(s1,s2)<<endl; = cout<<(s1.size()<s2.s ...

  5. 不可或缺的 sendEmail

    还在为Linux下没有便捷的邮件程序苦恼,还在为复杂的邮件服务器架设Google N多网页? 对于小型,便捷的Linux下命令行邮件程序,sendEmail使得这一切变得轻松可行.一起来看看吧. 一. ...

  6. 点线图中的A&ast;算法

    A*简介 A*(A-Star)算法是一种启发式算法,是静态路网中求解最短路最有效的方法.公式表示为:f(n)=g(n)+h(n), 其中f(n) 是节点n从初始点到目标点的估价函数, g(n) 是在状 ...

  7. (转)ASP&period;NET-关于Container dataitem 与 eval方法介绍

    Container是一个数据容器,代表集合类或者dataview中的一行,而Container.dataitem代表该行的数据:所有的container   被存 放在是一个栈堆stack中,自动的将 ...

  8. NP-难题

    所谓NP-难题,在给定的一个信息系统中,假设研究对象书目为m,属性书目为n,则要考察的属性集P的一个子集是否为最小子集,要进行n*m*m次的比较.而n个属性可构成2的n次方个子集,这些子集都有可能是最 ...

  9. Nagios显示器mysql定从库&colon; libmysqlclient&period;so&period;18&colon; cannot open shared object file&colon; No such

    做mysql的slave时间监控,必须check_mysql文字,check当误差: error while loading shared libraries: libmysqlclient.so.1 ...

  10. 论文笔记(4):Fully Convolutional Networks for Semantic Segmentation

    一.FCN中的CNN 首先回顾CNN测试图片类别的过程,如下图: 主要由卷积,pool与全连接构成,这里把卷积与pool都看作图中绿色的convolution,全连接为图中蓝色的fully conne ...