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. Java Web应用中获取用户请求相关信息,如:IP地址、操作系统、浏览器等信息

    引入jar包 <dependency> <groupId>eu.bitwalker</groupId> <artifactId>UserAgentUti ...

  2. Asp.Net Core 进阶(二) —— 集成Log4net

    Asp.Net Core 支持适用于各种内置日志记录API,同时也支持其他第三方日志记录.在我们新建项目后,在Program 文件入口调用了CreateDefaultBuilder,该操作默认将添加以 ...

  3. CPP-基础:char、BYTE、byte

    一,C++语言的内建类型中没“BYTE”这么个类型.BYTE是WINDOWS Platform SDK中windef.h里面定义的:typedef unsigned char BYTE; 二,char ...

  4. linux设置http/https proxy及忽略proxy的方法

    msys2设置网络代理 在文件 .bashrc 中添加 export http_proxy="proxy IP:port" 如 export http_proxy="19 ...

  5. iOS7.1企业版发布后用户通过sarafi浏览器安装无效的解决方案

    关于iOS7.1企业版发布后,用户通过sarafi浏览器安装无效的解决方案: 通过测试,已经完美解决. 方案一: iOS7.1企业应用无法安装应用程序 因为证书无效的解决方案 http://blog. ...

  6. Codeforces Round #510 #C Array Product

    http://codeforces.com/contest/1042/problem/C 给你一个有n个元素序列,有两个操作:1,选取a[i]和a[j],删除a[i],将$a[i]*a[j]$赋值给a ...

  7. Leetcode 9 回文数Palindrome Number

    判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: 输入: -121 输出: false 解释: 从左向 ...

  8. day18-python之迭代器和生成器

    1.文件处理模式b模式 #!/usr/bin/env python # -*- coding:utf-8 -*- # f=open('test.py','rb',encoding='utf-8') # ...

  9. 数据结构( Pyhon 语言描述 ) — — 第6章:继承和抽象类

    继承 新的类通过继承可以获得已有类的所有特性和行为 继承允许两个类(子类和超类)之间共享数据和方法 可以复用已有的代码,从而消除冗余性 使得软件系统的维护和验证变得简单 子类通过修改自己的方法或者添加 ...

  10. Spring,Mybatis,Springmvc框架整合项目(第一部分)

    一.说在前面的话 本篇博文实现一个注册登录小项目,使用spring,mybatis,springmvc框架进行整合,我们创建的是一个maven工程,主要是方便jar包版本的管理.项目使用eclispe ...