東北四省賽 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;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章