2018东北四省赛 Spell Boost DP

7233: Spell Boost

时间限制: 1 Sec  内存限制: 128 MB
提交: 68  解决: 11
[提交] [状态] [讨论版] [命题人: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

题意:给n张牌,总体力w,每张牌需要花费wi造成xi的伤害,同时每张牌可能会有两个属性,第一个属性可以在使用时使所有具

有第二种属性的牌的w减1,计算最大伤害

思路:DP,似乎每次看之前都觉得很难,看懂了又觉得挺简单,都没啥可讲的,太菜了

代码:

#include <bits/stdc++.h>

using namespace std;

const int maxn = 505;
int n, w;
int dp[2][maxn][maxn];
struct node {
    int w, x, ma, bo;
} s[maxn];

bool cmp(node a, node b) {
    if (a.ma != b.ma) return a.ma > b.ma;
    if (a.bo != b.bo) return a.bo < b.bo;
    return a.w < b.w;
}

int main() {
    scanf("%d%d", &n, &w);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d%d%d", &s[i].w, &s[i].x, &s[i].ma, &s[i].bo);
    }
    sort(s+1, s + n+1, cmp);
    memset(dp[0], -1, sizeof(dp[0]));
    dp[0][0][0] = 0;
    for (int i = 1; i <= n; i++) {
        memset(dp[i % 2], -1, sizeof(dp[i % 2]));
        for (int j = 0; j <= i; j++) {
            for (int k = 0; k <= w; k++) {
                if (dp[(i - 1) % 2][j][k] == -1) continue;
                dp[i % 2][j][k] = max(dp[i % 2][j][k], dp[(i - 1) % 2][j][k]);
                int jj = j + s[i].ma;
                int ww = k + max(0, s[i].w - j * s[i].bo);
                if (ww <= w)
                    dp[i % 2][jj][ww] = max(dp[i % 2][jj][ww], dp[(i - 1) % 2][j][k] + s[i].x);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= w; j++) {
            ans = max(ans, dp[n % 2][i][j]);
        }
    }
    printf("%d\n", ans);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/renzijing/article/details/82470320