Spell Boost
Spell Boost
时间限制: 1 Sec 内存限制: 128 MB
题目描述
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.
输入
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
输出
样例输入
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的更多相关文章
- HDOJ 6508 Problem I. Spell Boost (01背包/DP)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6508 题目: Problem Description Shadowverse is a funny car ...
- 2018年东北地区赛S - Problem I. Spell Boost HDU - 6508
题目地址:https://vjudge.net/problem/HDU-6508 思路:给一些卡,分为四种卡.1.白卡(没效果)2.魔法,作用卡(会对作用卡的费用减少,也会被魔法卡作用)3.作用卡(会 ...
- 2018 东北地区大学生程序设计竞赛(ABEHIK)
HDU6500:Problem A. Game with string 题意: 给你一个字符串s以及它的m个子串的首尾位置,现在Alice和 Bob两个人轮流在任一子串的前面或者后面加1个字符,要求加 ...
- boost强分类器的实现
boost.cpp文件下: bool CvCascadeBoost::train( const CvFeatureEvaluator* _featureEvaluator, int _numSampl ...
- Boost信号/槽signals2
信号槽是Qt框架中一个重要的部分,主要用来解耦一组互相协作的类,使用起来非常方便.项目中有同事引入了第三方的信号槽机制,其实Boost本身就有信号/槽,而且Boost的模块相对来说更稳定. signa ...
- 玩转Windows服务系列——使用Boost.Application快速构建Windows服务
玩转Windows服务系列——创建Windows服务一文中,介绍了如何快速使用VS构建一个Windows服务.Debug.Release版本的注册和卸载,及其原理和服务运行.停止流程浅析分别介绍了Wi ...
- boost::function的用法
本片文章主要介绍boost::function的用法. boost::function 就是一个函数的包装器(function wrapper),用来定义函数对象. 1. 介绍 Boost.Func ...
- Boost条件变量condition_variable_any
Boost条件变量可以用来实现线程同步,它必须与互斥量配合使用.使用条件变量实现生产者消费者的简单例子如下,需要注意的是cond_put.wait(lock)是在等待条件满足.如果条件不满足,则释放锁 ...
- 新手,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 ...
随机推荐
- 怎样配置JDK开发环境
(1)我们需要配置三个环境变量,分别是JAVA_HOME,CLASSPATH,Path (2)变量名输入:JAVA_HOME,变量值输入:D:\Java\jdk1.8.0_05点击确定. 需要特别注意 ...
- 使用office 365打开excel文件报错,提示“向程序发送命令时出现问题”
我买了一套正版的office 365装在我的windows10 上.但是每次打开excel都会报错,如图一.求教了微软技术人员,他们给出了以下办法: 图一 方法一: 修复安装Office ====== ...
- docker配置国内镜像
1. 配置 root@ros-OptiPlex-3050:~# cat /etc/docker/daemon.json { "graph": "/mnt/docke ...
- 【Linux】Ubuntu18.04镜像下载,新功能介绍
一.Ubuntu18.04镜像下载 官方下载地址:http://releases.ubuntu.com/18.04/ 官方64位iso下载地址:http://releases.ubuntu.com/1 ...
- 2.add two number
在初始化的时候:ListNode* result;这样就会报runtime error
- C++ static关键字
一.面向过程中的static 1.修饰全局变量(静态全局变量) (1)静态全局变量在全局数据区分配内存: (2)未经初始化的静态全局变量会被程序自动初始化为0: (3)静态全局变量在申明它的整个文件是 ...
- mysql:having 用法
顺序:where -> group by -> min -> order by -> limit 在select语句中使用having 子句来指定一组行或聚合的过滤条件 hav ...
- docker系列之网络配置
docker 网络配置 docker 安装后, 会自动在系统做一个网桥配置 docker0 . 其容器都会分配到此网桥配置下的独立, 私有 IP 地址. 如果你要自己配置桥接, 也可以把 docker ...
- jenkins插件开发(二)
https://wiki.jenkins.io/display/JENKINS/Extend+Jenkins http://commons.apache.org/proper/commons-jell ...
- python基础学习笔记——os模块
#OS模块 #os模块就是对操作系统进行操作,使用该模块必须先导入模块: import os #getcwd() 获取当前工作目录(当前工作目录默认都是当前文件所在的文件夹) result = os. ...