东北四省赛 Spell Boost

问题 I: Spell Boost

时间限制: 1 Sec  内存限制: 128 MB
提交: 63  解决: 8
[提交] [状态] [讨论版] [命题人:admin]

题目描述

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

题目大意是说给你一些费用,你有一些卡片,具有魔法或者攻击或者两者兼而有之的属性,每使用一张卡片都需要不同的费用,你每使用一张魔法卡,所有没使用过的具有攻击属性的卡片的费用都会减一,每使用一张具有攻击属性的卡,就能造成一定量的伤害,求最大伤害。

解法:i枚举现在用到第几张卡片,j为费用,k为已经打出了几张具有魔法属性的卡,用个滚动数组记录当前状态所能造成的最大伤害值即可。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 505;
int dp[505][505][2];
struct fun
{
    int a,b,flag1,flag2;
    int flag;
}z[maxn];
int cnt;
bool cmp(fun a, fun b)
{
    if (a.flag == 2 && b.flag == 2)
        return a.a > b.a;
    return a.flag > b.flag;
}
int main()
{
//    freopen("in.txt", "r", stdin);
    int n,w;
    scanf("%d%d", &n, &w);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d%d%d%d", &z[i].a, &z[i].b, &z[i].flag1, &z[i].flag2);
        if (z[i].flag1)
            cnt++;
        if (z[i].flag1)
        {
            if (z[i].flag2)
                z[i].flag = 2;
            else
                z[i].flag = 1;
        }
        else
        {
            if (z[i].flag2)
                z[i].flag = 3;
            else
                z[i].flag = 0;
        }
    }
    sort(z, z + n, cmp);
    int pre,now;
    pre = 1;
    now = 0;
    for(int i = 0; i < n; i++)
    {
        now ^= 1;
        pre ^= 1;
        for(int j = 0; j <= w; j++)
            for(int k = 0; k <= cnt; k++)
            {
                int tmp = z[i].a;
                int tmpk = k + z[i].flag1;
                if(z[i].flag2)
                    tmp = max(tmp - k, 0);
                dp[j][k][now] = dp[j][k][pre];
                if(tmp <= j && tmpk <= cnt)
                    dp[j][k][now] = max(dp[j][k][now], dp[j - tmp][tmpk][pre] + z[i].b);
            }
    }
    printf("%d\n", dp[w][0][now]);
    return 0;
}

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值